Looping more than once with the WordPress loop

When I decided to write my own WordPress theme, I thought a good approach would be to duplicate the default theme and go from there. Since that day I have rewritten much of the code. The loop in the index.php file, however, remains unchanged. The loop looks like this:

if (have_posts()) :
	while (have_posts()) : the_post();
		// code
	endwhile;
endif;

As well as displaying the three most recent posts on the home page, I wanted to display links to slightly older posts on the sidebar. I discovered a WpRecipes post on using two different WordPress loops which suggests adding the following line of code just before the loop:

query_posts('showposts=5&offset=3');

The offset ensures that posts do not appear in both places.

Leave a reply…

accepted tags
  • <a href="" title=""></a>
  • <abbr title=""></abbr>
  • <acronym title=""></acronym>
  • <blockquote cite=""></blockquote>
  • <cite></cite>
  • <code></code>
  • <del datetime=""></del>
  • <em></em>
  • <q cite=""></q>
  • <strike></strike>
  • <strong></strong>