2

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

  1. 索引.php

  2. 页脚.php

  3. 头文件.php

  4. 样式.css

  5. 截图.png

  6. css(文件夹)

  7. js(文件夹)

  8. 字体(文件夹)

  9. 图像(文件夹)

任何形式的帮助将不胜感激。

4

1 回答 1

1

不要在 index.php 中对所有 html 进行硬编码,而是使用 WP 循环创建模板,然后使用这些模板在 Wordpress Admin 中创建页面。例如,如果您使用的是 25 个 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。将其命名为“家”。将您的 html 动态内容放在内容区域中。选择您之前创建的模板 Front_Page(从右侧栏)。有关详细信息,请参阅 WP codex 链接:WordPress 静态首页流程

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

编辑1:您可以像传统方式那样将样式表和Js文件排入头文件中,也可以通过主题的function.php。有关信息,请参阅包括 CSS 和 JavaScriptwp_enqueue_style

编辑 2:是的,最好使用现有主题并对其进行自定义,或者使用现有主题WP Child Theme制作您自己的子主题

于 2016-04-14T08:47:51.007 回答