Running multiple loops in WordPress
Tags: the loop, wordpress
Date: 31st October, 2009
The homepage for this site displays the latest three blog posts for my learning blog and my webdev blog. These aren’t actually different blogs but two different categories in the same blog. However, the nature of the WordPress loop is that it would be impossible to display them like this on the same template.
To get around it I had to run two separate loops with their own queries before them:
<!– Begin first loop… –>
<?php query_posts(‘category_name=learning&showposts=3′); ?>
<?php while (have_posts()) : the_post(); ?>
<!– Content goes here… –>
<?php endwhile; ?>
<!– Reset the loop… –>
<?php rewind_posts(); ?>
<!– Begin second loop… –>
<?php query_posts(‘category_name=webdev&showposts=3′); ?>
<!– Content goes here… –>
<?php endwhile; ?>
Notice the rewind_posts() command? That’s the key as it resets the query from before. Here’s the original link: Multiple WordPress Loops Explained.