【问题标题】:Wordpress - if there are no posts to display for a single categoryWordpress - 如果没有帖子可显示单个类别
【发布时间】:2015-03-22 05:12:26
【问题描述】:

如果某个类别没有帖子,我会尝试显示消息

<?php $recent = new WP_Query("cat=9&showposts=10");
     while($recent->have_posts()) : $recent->the_post();?>
        <?php the_title(); ?>
        <?php the_content();?>
<?php endwhile; ?>

但是当我添加一个“else”时,我得到了空白屏幕

<?php else: ?>
message ////
<?php endif; ?>

【问题讨论】:

    标签: php wordpress categories posts


    【解决方案1】:

    你可以做这样的事情 <?php if ( have_posts() ) { while ( have_posts() ) : the_post(); // Your loop code endwhile; } else { echo 'Sorry, no posts were found'; } ?>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多