2013-04-28 52 views
0

我做了我的第一个主题,它非常适合编辑更新页面等,但不会显示任何帖子。WordPress的“循环”不显示在我的主题的博客文章

我已将“循环”放入模板页面(从第21个主题复制而来),因为我只希望帖子出现在该页面上。我已将博文设置为显示在此页面上(来自设置页面),但仍然没有显示。

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

任何想法有什么不对?

<?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

你分配此模板的page..Go页面,并设置默认模板中列出的项目选择... – 2013-04-28 03:09:32

+1

2 ENDIF一个如果?? !!! – 2013-04-28 04:22:08

+1

如果这是你的整个代码,你应该得到空白页面,因为你有<?php endif; //结束current_user_can()检查?>但没有,如果语句。 – user850010 2013-04-28 09:54:35

回答

1

帖子总是会出现在index.php模板,除非你改变“头版显示”选项Settings=>Reading,在这里看到,例如:http://imgur.com/izwa5yw如果你有这一套用于展示博客文章一个页面(在图片中),那么任何页面(博客)都必须将默认模板(在页面编辑屏幕中)设置为您在文件的模板名称部分编写的值(在您的案例博客),泰米尔说。

更新:您必须回显get_template_part()或它不会显示。您可以使用the_content()代替首选。任何以_输出自身开始的变量。 get_变量不会输出它们自己。

<?php echo get_template_part(); ?> 

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