Query within Query?
-
At the top of my site, just before the main loop, I have a query that pulls the posts from a certain category. Now I got that to work fine but I wanted to step it up a notch…
The section is designed so the big main div shows the latest post from a category, while inside that box a small section shows the other posts by date from the same category, using an offset condition.
However that’s how I see it on paper, how do I integrate the two queries so one can work within the other.
Basically it would be:
<?php $my_query = new WP_Query(‘category_name=featured&showposts=1’); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
[HTML showing one post]====== sub query =======
<?php $my_query = new WP_Query(‘category_name=featured&showposts=3&offset=1’); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
[HTML sub stuff with 1 post offset]
<?php endwhile; ?>
====== sub query =======<?php endwhile; ?>
Obviously wrapping a query within a query like what I did above doenst make sense… so how do I do it?
- The topic ‘Query within Query?’ is closed to new replies.