0

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?

2 Answers 2

1

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.

0

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

0

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.