您可以检查查询中是否有if( $your_query->have_posts() )
, 并且仅当容器通过该测试时才输出该容器。
$featuredPosts = new WP_Query( array(
\'posts_per_page\' => 2,
\'cat\' => 6,
\'offset\' => 4
) );
if ( $featuredPosts->have_posts() ) :
echo(\'<ul class="right-hang">\');
while ( $featuredPosts->have_posts() ) :
$featuredPosts->the_post();
endwhile;
echo \'</ul>\';
endif;