繁体   English   中英

Wordpress“循环”未在我的主题中显示博客文章

[英]Wordpress “loop” not showing blog posts in my theme

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

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

这是我的模板页面显示博客文章的代码。

知道有什么问题吗?

<?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更改“首页显示”选项,请参见此处,例如: http : //imgur.com/izwa5yw如果您设置了此项以显示博客在页面上发布(位于图像中),则无论是哪个页面(博客),都必须将默认模板(在页面编辑屏幕中)设置为您在文件的模板名称:部分(在您的案例博客),如泰米尔语所说。

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

<?php echo get_template_part(); ?>

<?php the_content() ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM