Php Wordpress";“循环”;不在我的主题中显示博客帖子

Php Wordpress";“循环”;不在我的主题中显示博客帖子,php,html,wordpress,Php,Html,Wordpress,我制作了我的第一个主题,它非常适合编辑更新页面等,但不会显示任何帖子 我把“循环”放在一个模板页面中(从Twenty12主题复制),因为我只希望帖子出现在该页面上。我已将博客帖子设置为显示在此页面上(从“设置”页面),但仍然没有显示任何内容 下面是我的模板页面代码,用于显示博客文章 知道怎么了吗 <?php /** * Template Name: blog * * Full width page template with no sidebar. * * @package Myfirs

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

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

下面是我的模板页面代码,用于显示博客文章

知道怎么了吗

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


帖子将始终显示在index.php模板中,除非您更改
Settings=>Reading
中的“FrontPage displays”选项,请参见此处示例:如果您将此设置为在页面(在图像中)上显示博客帖子,则无论是哪个页面(博客),都必须使用默认模板(在页面编辑屏幕中)设置为您在文件(在您的博客中)的模板名称部分中写入的值,如泰米尔所说

更新:您必须回显
get\u template\u part()
,否则它不会显示。您可以使用
the\u content()
,这是首选。任何以输出本身开始的变量。get\u变量本身不会输出

<?php echo get_template_part(); ?>

<?php the_content() ?>


您是否已将此模板分配给页面..转到页面并将默认模板设置为在列出的项目中选择…两个endif和一个if???!如果这是您拥有的全部代码,您应该得到空白页面,因为您没有if语句。