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.

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

2 Answers

You can do it using the following loop:

<?php

$cat_477 = new WP_Query(); 
$cat_477->query('cat=477&showposts=4');
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
add comment

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

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.