首页 > 解决方案 > page.php 正在加载 wordpress 帖子而不是 single.php

问题描述

我对wordpress很陌生。所以面对这个问题。在我的 wordpress 博客中,我不知道为什么 page.php 正在加载单个 wordpress 帖子而不是 single.php。

我在 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.
 */

get_header(); ?>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
    the_content();
    endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>

<?php get_footer();

单.php:

<?php
/* The file for displaying single posts */
?>

<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
    <div class="blog-heading">
        <div class="container">
            <h1 class="text-center"><?php the_title(); ?></h1>
        </div>
    </div>
    <section class="blog-section">
        <div class="container">
            <div class="row">
                <div class="col-md-8">
                    <?php $featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
                    if ( ! empty( $featured_image_url ) ) { ?>
                        <div class="blog-item-thumbnail single">
                            <?php the_post_thumbnail(); ?>
                            <div class="blog-item-date">
                                <?php the_time('m'); ?><br>
                                <span><?php the_time('M'); ?></span>
                            </div>
                        </div>
                    <?php } else { ?>
                        <div class="blog-item-date single">
                            <?php the_time('m'); ?><br>
                            <span><?php the_time('M'); ?></span>
                        </div>
                    <?php } ?>
                    <div class="blog-item-info">
                        <ul>
                            <li><i class="fa fa-user"></i><?php the_author(); ?></li>
                            <li><i class="fa fa-folder-open"></i><?php the_category(', '); ?></li>
                        </ul>
                    </div>
                    <div class="clear"></div>
                    <div class="blog-single-nav row">
                        <div class="col-sm-2 blog-single-nav-previous"><?php previous_post_link('%link', '<i class="fa fa-angle-left"></i> Prev'); ?></div>                     
                        <div class="col-sm-8 addthis_inline_share_toolbox"></div>
                        <div class="col-sm-2 blog-single-nav-next"><?php next_post_link('%link', 'Next <i class="fa fa-angle-right"></i>'); ?></div>
                    </div>
                    <div class="blog-single-content">
                        <?php the_content(); ?>
                    </div>
                    <div class="blog-single-nav row">
                        <div class="col-sm-2 blog-single-nav-previous"><?php previous_post_link('%link', '<i class="fa fa-angle-left"></i> Prev'); ?></div>                     
                        <div class="col-sm-8 addthis_inline_share_toolbox"></div>
                        <div class="col-sm-2 blog-single-nav-next"><?php next_post_link('%link', 'Next <i class="fa fa-angle-right"></i>'); ?></div>
                    </div>
                    <div class="blog-single-author row">          
                        <div class="col-sm-2 col-xs-3">
                            <?php userphoto_the_author_thumbnail() ?>
                        </div>
                        <div class="col-sm-10 col-xs-9">
                            <h5>About <?php echo get_the_author_meta( 'display_name' ); ?></h5>
                            <p><?php echo get_the_author_meta( 'description' ); ?></p>
                        </div>
                    </div>
                    <div class="blog-single-comments">
                        <?php echo do_shortcode('[fbcomments width="100%" count="off" num="5"]'); ?>
                    </div>
                </div>
                <div class="col-md-4 blog-sidebar">
                    <?php get_sidebar(); ?>
                </div>
            </div>
        </div>
    </section>
<?php endwhile; ?>
<?php get_footer(); ?>

每当我在 url http://www.example.com/blog/my-test-post/上加载单个帖子时,都会使用 page.php,而不是 single.php。我找不到原因。

标签: wordpress

解决方案


这是有趣的。

尝试...

  1. 禁用所有插件,看看问题是否仍然存在。
  2. 转到设置->永久链接并点击保存更改按钮,再次查看问题是否仍然存在。
  3. 从您的主题中删除 page.php,看看会发生什么。它是 404 还是使用 single.php

这些只是一些基本的故障排除技巧,可能会引导您朝着正确的方向前进。


推荐阅读