Free Wordpress Blog Setup

How to Exclude Latest Post from the WordPress Post Loop

By Editorial Staff in Themes
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

What Next?

Digg it
Save This Page
Subscribe to WPBeginner
Stumble it
Free Wordpress Blog Setup

Comments

4 Responses to “How to Exclude Latest Post from the WordPress Post Loop”
  1. Morning Copy says:

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

  2. dominik says:

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

  3. Jeremy says:

    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.

Share Your Opinions

Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!

Please make sure that you have read our Comment Policy.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar