对于标准查询,您可以通过以下方式检查帖子数量:
查询的所有帖子:$wp_query->found_posts
以及页面上的帖子:$wp_query->post_count
将其与条件语句一起使用,以切换到不同的布局。
示例:
<?php if ( have_posts() ) : //start of the loop//
if ( $wp_query->found_posts <= 4 ) { ?>
list output of posts
//this will need to include the \'while(have_posts())\' including the \'endwhile\' of the loop
<?php } else { ?>
float block output
//this will need to include the \'while(have_posts())\' including the \'endwhile\' of the loop
<?php }
endif; ?>