我是 WordPress 新手。我最近制作了自己的 html 网站并将其转换为 WordPress。它在 WordPress 中运行良好。但是有一个问题,那就是我无法通过 WordPress 更改网站的内容。也许是因为我在主题的 index.php 中编码了 html,但我不确定这是否有任何效果。 现在我的主题有以下文件:
index.php
footer.php
header.php
样式.css
截图.png
css(文件夹)
js(文件夹)
字体(文件夹)
img(文件夹)
我们将不胜感激任何形式的帮助。
最佳答案
不要在 index.php 中对所有 html 进行硬编码,而是使用 WP 循环创建模板,然后使用这些模板在 Wordpress Admin 中创建页面。例如,如果您使用的是 2015 Wordpress 主题,您的主模板可以与此类似:
<?php
/**
* The main template file
* Template Name: Front_Page
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* e.g., it puts together the home page when no home.php file exists.
*
* Learn more: {@link https://codex.wordpress.org/Template_Hierarchy}
*
* @package WordPress
* @subpackage Twenty_Fifteen
* @since Twenty Fifteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php endif; ?>
<?php
// Start the loop.
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
// End the loop.
endwhile;
// Previous/next page navigation.
the_posts_pagination( array(
'prev_text' => __( 'Previous page', 'twentyfifteen' ),
'next_text' => __( 'Next page', 'twentyfifteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>',
) );
// If no content, include the "No posts found" template.
else :
get_template_part( 'content', 'none' );
endif;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
然后创建首页:在页面中选择添加新页面。将其命名为“家”。将您的 html 动态内容放在内容区域中。选择您之前创建的模板 Front_Page(从右侧栏)。有关详细信息,请参阅 WP codex 链接:WordPress Static Front Page Process
现在要更改页面内容,您只需在 WP 管理面板中编辑页面即可。希望这会有所帮助。
编辑 1:您可以像传统方式一样在头文件中排队样式表和 Js 文件,也可以通过主题的 function.php 排队。参见 Including CSS & JavaScript和 wp_enqueue_style获取信息。
编辑 2:是的,最好使用现有主题并自定义它,或者使用现有主题制作您自己的子主题 WP Child Theme
关于html - 无法将我的 html 编辑为 wordpress 上的 wordpress 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36617389/