Multiple loops + get_posts : how to avoid duplication

$posts = get_posts('numberposts=10&offset=1'); foreach ($posts as $post): setup_postdata($post);

The code above resets the counter, and re-runs the loop. The offset can be set to whatever you want, the default is 0.

To avoid duplication, you need to test against the first post in the second loop  :  

while($top_query->have_posts()) : $top_query->the_post(); $first_post = $post->ID;

Then the new second loop:

query_posts('showposts=6'); ?> <?php while(have_posts()) : the_post(); if(!($first_post == $post->ID)) :

~ template tags 'n stuff go here ~

endif; endwhile;

query_posts offset

see also here here

The solution also works if you want to get the posts displayed in columns. Use a query for each column and display the result in the appropriate div.


~ by netlex on May 1, 2006.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: