Using query_posts to show different categories
-
Hello!
I’m trying to use query_posts to split up the main page of my site (home.php) in the following way – I want to show 2 posts from one category, then show 1 post from a separate category, then show 6 posts from the same category I showed first.
So, basically I want to show 2 posts from category 1, then 1 post from category 2, then show 6 posts from category 1, all on the same page.
Is query_posts the easiest way to go about this? Would this be an appropriate way to use it?
<?php global $query_string; query_posts($query_string . "&order=ASC"); ?> <?php query_posts('category_name=cat1&posts_per_page=2'); ?> <?php while (have_posts()) : the_post(); ?> <!-- Do special_cat stuff... --> <?php endwhile;?> <?php $my_query = new WP_Query('category_name=cat2&posts_per_page=1'); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <!-- Do special_cat stuff... --> <?php endwhile; ?> <?php $my_query2 = new WP_Query('category_name=cat&posts_per_page=6'); ?> <?php while ($my_query2->have_posts()) : $my_query->the_post(); ?> <!-- Do special_cat stuff... --> <?php endwhile; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Using query_posts to show different categories’ is closed to new replies.