我想在主页上使用多个循环。首先,我想要显示特定类别的帖子,然后显示所有帖子,包括我上面包含的类别。但是,当我在没有使用query_posts的情况下使用第二个循环时,前一个循环的posts被排除在外。
例如:
<div class="special_category" >
<?php query_posts('category_name=special_cat&posts_per_page=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<!-- will get special_cat posts -->
<?php endwhile;?>
</div>
<div class="latest_posts">
<!-- as i want do display all posts, so I don't use query_posts. -->
<?php while (have_posts()) : the_post(); ?>
<!-- this will exclude the posts of above special_cat -->
<?php endwhile;?>
</div>
如果我在第二个循环中使用query_string (即使没有传递任何参数),那么它将包含posts。
<div class="latest_posts">
<!-- i used query_posts without any arguments -->
<?php query_posts(''); ?>
<?php while (have_posts()) : the_post(); ?>
<!-- now this will get all posts -->
<?php endwhile;?>
</div>
所以我的问题是,它是这样工作的吗,即。排除上面循环中的帖子,或者我做错了什么?为什么在不使用query_posts的情况下不能得到所有的帖子?谢谢。
发布于 2012-04-23 11:25:32
第一个查询将影响第二个循环,直到您将其重置
在第一个循环后添加<?php wp_reset_query(); ?>
更多信息请点击此处http://codex.wordpress.org/Function_Reference/wp_reset_query
发布于 2012-04-23 12:42:32
如果你使用多个posts循环,你应该使用wp_query。
这样一来,您也不必重置查询。
https://stackoverflow.com/questions/10279568
复制