【问题标题】:Wordpress: cannot see content in page.php, only sidebarWordpress:看不到 page.php 中的内容,只有侧边栏
【发布时间】:2025-12-31 17:20:03
【问题描述】:

我创建了自己的主题,并将其他标准 Wordpress 主题中的代码复制并粘贴到我的 page.php 中,但它不会显示内容,只有在代码需要时显示侧边栏。

我从 Twentyseventeen 复制的 page.php 代码示例:

<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>

<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <?php
            while ( have_posts() ) : the_post();

                get_template_part( 'template-parts/page/content', 'page' );

                // If comments are open or we have at least one comment, load up the comment template.
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;

            endwhile; // End of the loop.
            ?>

        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .wrap -->

<?php get_footer();

我已经创建了许多不同的自定义页面模板,它们都可以很好地显示内容。

我已经使用默认模板 (page.php) 创建了一个非常标准的新页面,并在管理面板中添加了文本(因此不是直接添加到模板中),但是该文本或任何简码或其他输入都没有查看完成的页面时显示。

无法弄清楚缺少什么。任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我假设您在 template-parts/page 中没有文件 content-page.php?如果没有,请从 Twentyseventeen 主题复制并粘贴整个 template-parts 文件夹,或者替换行 'get_template_part('template-parts/page/content', 'page');'用 'the_content();'

    【讨论】:

    • 谢谢!我以为它会是这样的,现在试试看(y)。
    • 没问题!请您将我的答案标记为正确吗?