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

share|improve this question
    
is the category list '5,2,4,3,1' always the same, or likely to change? –  Michael Mar 5 '12 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 Mar 5 '12 at 20:35

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
work perfectly.... make it as a plugin and you be famous !... here you can see it live : mecanomedic.com –  menardmam Mar 6 '12 at 19:31

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.