Use two different WordPress loops
October 27, 2008 · Print This Article
Maybe you wants to get the most recent posts first, and later create a new loops getting the 5 next posts, excluding the most recent post.
To achieve what you wants to do, we have to use the query_posts() function with the showposts and offset parameters.
The first loop:
query_posts('showposts=1'); // First loop, we only get the most recent post
if (have_posts()) :
while (have_posts()) : the_post(); ?>
// WordPress loop
endwhile;
endif; ?>
The second loop:
query_posts('showposts=5&offset=1'); // Second loop, we get 5 posts excluding the most recent.
if (have_posts()) :
while (have_posts()) : the_post(); ?>
// WordPress loop
endwhile;
endif; ?>
A little explanation about query_posts() parameters we used here:
showposts=5 specifies that you only wants to get 5 posts.
offset=1 specifies that you don’t want to get the 1st most recent post.





















Comments
Got something to say?
You must be logged in to post a comment.