Wordpress“循环”没有在我的主题中显示博客帖子

时间:2013-04-28 03:04:35

标签: php html wordpress

我已经制作了我的第一个主题,它非常适合编辑更新页面等,但不会显示任何帖子。

我已将“循环”放在模板页面中(从二十世纪主题复制),因为我只希望帖子显示在该页面上。我已将博客帖子设置为显示在此页面上(从设置页面),但仍然没有显示任何内容。

以下是我显示博客帖子的模板页面的代码。

知道什么是错的吗?

<?php
/**
*  Template Name: blog
*
* Full width page template with no sidebar.
*
* @package Myfirsttheme
* @subpackage Template
*/

get_header(); ?>

    <?php if ( have_posts() ) : ?>

        <?php /* Start the Loop */ ?>
        <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'content', get_post_format() ); ?>
        <?php endwhile; ?>

    <?php else : ?>

        <article id="post-0" class="post no-results not-found">
            <div class="entry-content">
                <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
                <?php get_search_form(); ?>
            </div><!-- .entry-content -->
        <?php endif; // end current_user_can() check ?>

        </article><!-- #post-0 -->

    <?php endif; // end have_posts() check ?>

    </div><!-- #content -->
</div><!-- #primary -->

<?php get_footer(); ?>

1 个答案:

答案 0 :(得分:1)

帖子将始终显示在index.php模板中,除非您更改Settings=>Reading中的“首页显示”选项,请参阅此处,例如:http://imgur.com/izwa5yw如果您有这个设置来显示页面上的博客帖子(在图像中),然后任何页面(博客)必须将默认模板(在页面编辑屏幕中)设置为您在模板名称中写入的值:正如泰米尔所说,你文件的一部分(在你的案例博客中)。

更新:您必须回显get_template_part(),否则它将不会显示。您可以使用the_content()代替首选。任何以__输出开头的变量。 get_变量不会自己输出。

<?php echo get_template_part(); ?>

<?php the_content() ?>
相关问题