if(have_posts()):
while(have_posts()):
the_post();
the_content();
endwhile;
endif;
如果没有if条件,以下代码也可以正常工作:while(have_posts()):
the_post();
the_content();
endwhile;
谢谢。if(have_posts()):
while(have_posts()):
the_post();
the_content();
endwhile;
endif;
如果没有if条件,以下代码也可以正常工作:while(have_posts()):
the_post();
the_content();
endwhile;
谢谢。您只需要if ( have_posts() ) :
如果,作为函数suggets的名称,如果没有帖子,您需要做一些不同的事情。这类似于显示“找不到帖子”消息
但你只需要在那些可以不显示帖子的模板上使用,比如归档和搜索。对于单个帖子和页面模板if
是不必要的。
你说得对,没必要。
但是,您通常希望将post输出包装在<div class="posts">
或者类似的东西,您可以根据div中是否有任何内容来设置输出div的条件,这在我看来会使样式更加清晰,因为最终不会<div class="posts"></div>
如果没有帖子。您不需要使用任何:empty
CSS中的选择器来隐藏这个空div,因为它根本不在DOM中。
我想用这个循环显示最后3篇文章。这很有效,但我不知道为什么,但摘录总是一样的。我做错了什么? <?php $args = array( \'numberposts\' => \'3\' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ ?> <div class=\"