admin管理员组文章数量:1026125
I am using Isotope jquery plugin to filter/sort posts in Wordpress but to correctly filter the posts into the right order I have needed to output each category one after the other. To do this I've created one custom query for each category (4 categories in total, therefore 4 queries). You can see my working code here: .
I would like to convert these 4 queries into just one query but this one query must display these 4 categories one after the other (like it does currently).
The reason why I want this, is because I'd like to add Infinite scroll functionality to grab the next batch of posts regardless of what category they are in. In order for this to work I need to add pagination and figured pagination wouldn't work correctly with 4 separate loops. However, if anyone can implement pagination into my existing code without having to re-write it then I'm all ears.
I am using Isotope jquery plugin to filter/sort posts in Wordpress but to correctly filter the posts into the right order I have needed to output each category one after the other. To do this I've created one custom query for each category (4 categories in total, therefore 4 queries). You can see my working code here: http://pastebin/LTDmbbLf.
I would like to convert these 4 queries into just one query but this one query must display these 4 categories one after the other (like it does currently).
The reason why I want this, is because I'd like to add Infinite scroll functionality to grab the next batch of posts regardless of what category they are in. In order for this to work I need to add pagination and figured pagination wouldn't work correctly with 4 separate loops. However, if anyone can implement pagination into my existing code without having to re-write it then I'm all ears.
Share Improve this question asked Nov 3, 2012 at 12:09 egr103egr103 3051 gold badge5 silver badges17 bronze badges1 Answer
Reset to default 0You can refer this.
Use the examples part. Inside the foreach loop put your all the code which needs to be repeated for each category type.
something like:
<?php
$categories = get_the_category();
if($categories){
foreach($categories as $category) {
$my_query = new WP_Query('cat=$category->term_id');
//code to display category posts goes here
}
}
?>
You are ready to go with this.
I am using Isotope jquery plugin to filter/sort posts in Wordpress but to correctly filter the posts into the right order I have needed to output each category one after the other. To do this I've created one custom query for each category (4 categories in total, therefore 4 queries). You can see my working code here: .
I would like to convert these 4 queries into just one query but this one query must display these 4 categories one after the other (like it does currently).
The reason why I want this, is because I'd like to add Infinite scroll functionality to grab the next batch of posts regardless of what category they are in. In order for this to work I need to add pagination and figured pagination wouldn't work correctly with 4 separate loops. However, if anyone can implement pagination into my existing code without having to re-write it then I'm all ears.
I am using Isotope jquery plugin to filter/sort posts in Wordpress but to correctly filter the posts into the right order I have needed to output each category one after the other. To do this I've created one custom query for each category (4 categories in total, therefore 4 queries). You can see my working code here: http://pastebin/LTDmbbLf.
I would like to convert these 4 queries into just one query but this one query must display these 4 categories one after the other (like it does currently).
The reason why I want this, is because I'd like to add Infinite scroll functionality to grab the next batch of posts regardless of what category they are in. In order for this to work I need to add pagination and figured pagination wouldn't work correctly with 4 separate loops. However, if anyone can implement pagination into my existing code without having to re-write it then I'm all ears.
Share Improve this question asked Nov 3, 2012 at 12:09 egr103egr103 3051 gold badge5 silver badges17 bronze badges1 Answer
Reset to default 0You can refer this.
Use the examples part. Inside the foreach loop put your all the code which needs to be repeated for each category type.
something like:
<?php
$categories = get_the_category();
if($categories){
foreach($categories as $category) {
$my_query = new WP_Query('cat=$category->term_id');
//code to display category posts goes here
}
}
?>
You are ready to go with this.
本文标签: postsConverting multiple loops into one single loop with pagination
版权声明:本文标题:posts - Converting multiple loops into one single loop with pagination 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745627068a2159927.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论