Mr Portman

School website critiques, articles on education and some random cod

Running multiple loops in WordPress

Tags: ,

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.

August 2010

July 2010

June 2010

May 2010

April 2010

February 2010

January 2010

December 2009

November 2009

October 2009

September 2009