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?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
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.
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