2012-12-29 230 views
1

我需要在类别中显示标题,并且只有在WordPress中的类别中有帖子时才能显示该标题。标题不应放在每个帖子上。它如何解决?仅在WordPress中的类别中有帖子时显示标题

我现在的代码:

<?php query_posts('category_name=onestar&showposts=5'); ?> 
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
     <div class="wrapper orangecolor"> 
      <article class="intro"> 
       <h2><?php the_title(); ?></h2> 
       <div><?php the_content(); ?></div> 
      </article> 
     </div> 
<?php endwhile; ?> 
<?php endif; ?> 
+0

你应该while循环前添加标题。 –

+0

昨天我在WordPress的支持论坛上发现了类似于它的东西,其标题在“:while”之前,但最终出现在PHP错误中。它应该如何编码? –

回答

0
<?php query_posts('category_name=onestar&showposts=5'); ?> 
<?php if (have_posts()) : ?> 
    Put the header here 
    <?php while (have_posts()) : the_post(); ?> 
     <div class="wrapper orangecolor"> 
      <article class="intro"> 
       <h2><?php the_title(); ?></h2> 
       <div><?php the_content(); ?></div> 
      </article> 
     </div> 
    <?php endwhile; ?> 
<?php endif; ?> 
+0

工作就像一个魅力,谢谢! –

相关问题