How to Exclude Latest Post from the WordPress Post Loop

Posted on March 13th, 2010 by in Themes | 21 Comments  
How to Exclude Latest Post from the WordPress Post Loop

Excluding latest posts from the loop and/or offset posts in the loop is one of the things that comes in handy when editing or designing themes. In this article we will show you how you can use the offset parameter in wp_query function to exclude latest posts from the WordPress post loop.

First you will need to find the loop that you are working with. Then you will need to add the following parameter:

query_posts('posts_per_page=5&offset=1');

This query is telling the loop to only display 5 posts which follow the most recent post (1). The important part in this code is “offset” and this magic word is doing the whole thing.

Your loop code should look like:

<?php
query_posts('posts_per_page=6&offset=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

This should be it. If you have any questions feel free to ask via comments.

Source: WP Codex

About

Editorial Staff at WPBeginner mainly Syed and David.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest
PabloCovarrubias 5 pts

hello, i just have one question, when i do this, pagination doesen0t work anymore, how can i fix this?

thanks, other than that, it works perfectly!!

cheers!

Thanks so much for this! I couldn't figure it out at all but this worked perfectly.

Is there a way to offset a post from one cat?

E.g I want to show all posts apart from the LATEST post of category x

Yes, you can just select category_in parameter, and add your category ID.

Thanks mate, you save my day :)

"query_posts('posts_per_page=6&offset=1');" this is not worked for me , while i am using the WP-PageNavi plugin for page navigation. :(

what error are you getting?

Thanks for the info. Worked well :) Though, I'm encountering another issue for another site I'm currently doing. Is there a way to exclude from the loop only the latest post of a particular category?

Thing is, I've a blog that publishes podcasts. The front page highlights the most recent podcast - posts are published under category: Podcast - via its own styling. At the same time, the front page also shows the last 5 most recent posts, of which may include posts under the category "podcast". I just don't want to show in the loop the most recent post published under "Podcast" simply because it's already featured with it's own styling. Hope you can help me out. thanks!

You can exclude all posts from the category "postcast" from your loop if you want. But there is no simple way of excluding just the latest post.

Thanks for the tip!
But I was wondering if there is also a way to exclude the post that is currently showed on screen.

If yes, can you tell me how to do this?

Thanks in advance!

Don't really understand your question? Which screen?

One of my pages displays first of all the latest or current post the user is viewing.

The current post is called by the loop.

Below this post I want to display the excerpts of other previous posts without the current post displayed in this list.

The previous post-excerpts are called by query_posts:

query('showposts=3&cat=5');
while($previousPosts->have_posts()) : $previousPosts->the_post();
?>

As you can see I call 3 posts(excerpts) from category 5 which displays three posts from category News. This seems ok but within these 3 post-excerpts, the current post which is called by the loop is also in this list.
Do you know a way to exclude the current post within this list?

Thanks again!

You can add offset=1 in the query to skip the first post.

Thanks again for the quick response!
However, I did try the offset=1 in the query, only thing is that when you press an older post, you get to see the older post in the main loop, within the list excerpts the latest post is excluded, but the older post which is now the current post is still in the excerpts list.

Any idea how to exclude not the latest but the current post?

Thanks so far already :)

Email us the live link to the site, so we can see exactly whats going on. Use the contact form for email.

Thank you so much for this piece as i was looking for a way to exclude 4 latest posts form my home page and i got answer by this articles and i have replaced (query_posts('posts_per_page=6&offset=1');) by query_posts('posts_per_page=6&offset=3'); and its done :)

Where exactly do you put this code to remove al posts but the sticky on the main page.

Thanks,

That is a multi-step process. First you would need to have a custom page template. Second you would need to create that custom page, your front page. Then you would run a query on that custom template showing only sticky posts.

Thanks, it was exactly what I was looking for! Thanks for any other hints.

Thanks for this. Nice solution for magazine-style layouts.

Tweets about us: