Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.com/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

1 Answer 1

You 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.

share|improve this answer
    
I do need to display specific stuff per category. Will what you've suggested work with this? –  egr103 Nov 3 '12 at 12:35
    
use the if condition inside the foreach so that you can do separate things for separate categories. –  Rohit Pande Nov 3 '12 at 12:36
    
Ok so, I'm trying the if condition but i'm not getting anything returned, any ideas? I'm trying to get the id of the category: <?php if ( $categories == 3 ) { ?> This is a Brand category <?php } ?> –  egr103 Nov 3 '12 at 13:03
    
<?php $categories = get_the_category(); if($categories){ foreach($categories as $category) { if($category->term_id == "some_id" ){ //do some category related stuff here }else if($category->term_id == "some_another_id" ){ //do some another category related stuff here } . . . . . //you can go to infinite possibilities in here } } ?> –  Rohit Pande Nov 3 '12 at 13:13
    
I can't seem to get this to work either, here's my new code: pastebin.com/UjYj03em –  egr103 Nov 3 '12 at 13:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.