page.php正在加载wordpress帖子,而不是single.php

时间:2019-12-03 18:49:30

标签: wordpress

我对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();

single.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(); ?>

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

1 个答案:

答案 0 :(得分:0)

这很有趣。

尝试...

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

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