WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have 3 categories (cat 1 , cat 2 , cat 3) , and my blog home page shows 6 recent posts . I want to show 2 recent posts from every category.

How can I do it?

share|improve this question

You can do it using the following loop:


$cat_477 = new WP_Query(); 
while($cat_477->have_posts()) : $cat_477->the_post(); ?>

        <h3><a href=" <?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <p><?php echo get_the_excerpt(); ?></p>

<?php endwhile; ?>

The number 477 is the ID of one category. The variable $cat_477 is where we save the MySQL query for one category (477 in this case). The number 4 is the number of posts to show.

You only need to know the ID of each category, change the numbers and create so many loops as you want.

share|improve this answer

As far as I know you can only do this by using multiple loops - one for each category. Hope this link helps: http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

share|improve this answer
thanks , gonna check that link – Shuvro Shuvro Dec 30 '12 at 12:36

Your Answer


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.