0

I like my homepage not to list only one category, but to list all category, group by post. Here is the request :

Cat

  • 1
  • 2
  • 3
  • 4
  • 5

and the post will be :

post

  • 1 (cat=2)
  • 2(cat=2)
  • 3(cat=1)
  • 4(cat=3)
  • 5(cat=4)
  • 6(cat=4)
  • 7(cat=4)
  • 8(cat=4)
  • 9(cat=5)

i like to list cat : 5,2,4,3,1 and when listing them, all the post from cat 5, then all the post from cat 2, and so on

So the result will be post :

  • 9
  • 1
  • 2
  • 5
  • 6
  • 7
  • 8
  • 4
  • 3

hope the example is clear enough to let you help me... thanks in advance

2
  • is the category list '5,2,4,3,1' always the same, or likely to change?
    – Michael
    Commented Mar 5, 2012 at 20:33
  • the category ID dont change, but i like to get all the category in the database.... but i want to choose the order... so i have no problem to hardcode it in shortcode or php if needed!
    – menardmam
    Commented Mar 5, 2012 at 20:35

1 Answer 1

1

here is a general structure how I would do it:

$categories = array(5,2,4,3,1); //manually enter the array of the category ids in the order how you want them to appear
  foreach( $categories as $cat ) { 
    $args = array( 
      'category__in' => array( $cat ), 
      'posts_per_page' => -1
      );
    $cat_query = new WP_Query( $args );
    if( $cat_query->have_posts() ) : while( $cat_query->have_posts() ) : $cat_query->the_post();
//enter here, whatever you want to show per post//
    endwhile;
    endif;
  } //end of foreach
1
  • work perfectly.... make it as a plugin and you be famous !... here you can see it live : mecanomedic.com
    – menardmam
    Commented Mar 6, 2012 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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