无法在wordpress上编辑我的html到wordpress主题

时间:2016-04-14 08:19:24

标签: html wordpress wordpress-theming custom-wordpress-pages

我是WordPress的新手。我最近创建了自己的html网站并将其转换为WordPress。它在WordPress中运行良好。但有一个问题,那就是我不能通过WordPress改变网站的内容。也许是因为我在我的主题的index.php中编码了html,但我不确定这是否有任何影响。 现在我的主题有以下文件:

  1. 的index.php

  2. footer.php

  3. 的header.php

  4. 的style.css

  5. screenshot.png

  6. 的CSS(文件夹)

  7. JS(文件夹)

  8. 字体(文件夹)

  9. IMG(文件夹)

  10. 非常感谢任何形式的帮助。

1 个答案:

答案 0 :(得分:1)

不要在index.php中对所有html进行硬编码,而是使用WP循环创建模板,然后使用这些模板在Wordpress Admin中创建页面。例如,如果您使用的是Twenty Fifteen 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(); ?>

然后创建一个Front Page:在Pages中选择Add New Page。标题为&#34; Home&#34;。将html动态内容放在内容区域中。选择您之前创建的模板Front_Page(从右侧栏开始)。有关详细信息,请参阅WP codex链接:WordPress Static Front Page Process

现在要更改页面内容,您只需编辑WP管理面板中的页面即可。希望这会有所帮助。

编辑1:您可以像传统方式一样在头文件中或通过主题的function.php将样式表和Js文件排入队列。有关信息,请参阅Including CSS & JavaScriptwp_enqueue_style

编辑2:是的,最好使用现有主题并使用现有主题WP Child Theme

制作自己的主题或制作自己的主题