Support » Plugins and Hacks » Looping the Loop

  • I have got my loop repeating but not in a way that is useful. As I want to run different queries in both loops presumably I need to swap the global variable as per Alexs stuff in Codex. But how is it put together ?. On loop 1; I am trying to get single post from a single cat and on loop 2;- 5 posts say from another single cat ? All code or prompts / hints gratefully received. TY.

Viewing 1 replies (of 1 total)
  • You can try this;

    on the first loop, do as you would normally. On the second loop however, you create a new WP_Query object (which is what handles the actions and properties for the_loop) via:
    <?php $sub_query = new WP_Query('category_name=site&showposts=5'); ?>

    Now you can loop through this wp_query object as you would normally:
    <?php while ($sub_query->have_posts()) : $sub_query->the_post(); ?>
    <?php endwhile; ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Looping the Loop’ is closed to new replies.