• Home
  • Contact

How To Display Just the Sticky Post on Front Page in WordPress

By Sridhar Katakam · Comments (10) · Tuesday, July 13th, 2010

Scenario

Settings -> Reading: Front page is set to display latest blog posts.

Blog pages show at most set to 1

When sticky post is the latest

In this case, only the sticky post is shown on the front page just like how we want.

When there are other published posts newer than the sticky post

In this case, 2 posts will be shown on the blog’s front page: the sticky post at the top and the latest post below it.

Solution

To fix this and have only the sticky post show up, add the following above the if/while statement that’s used to check the existence of posts (just above the loop) in index.php:

<?php
$sticky = get_option( 'sticky_posts' );
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1, 'orderby' => ID, 'showposts' => 2 ) );
?>

Screenshot

Source: http://wptricks.net/display-a-sticky-post-only/

Related Posts

  • No Related Post
Categories : WordPress
Tags : Sticky
  • Bilal Ahmed

    That’s really, that is what i was looking for, i got so many options but nothing solved it, had checked the option but it also failed, keep giving me 10 posts on the top page.

    Thanks alot for the help

    • Ufsugar

      Finally!! Thank you!!!

  • http://www.mactonweb.com/web-design-company-united-kingdom.html web design london

    That’s really great., that is what i was looking for it.Thanks for sharing it.

  • http://www.marathonm2m.com/m-to-m-security-sector/container-tracking.aspx container tracking

    Thanks for sharing ….. great witrh disqus…

  • http://datarecoveryfromcrashedharddrive.net Josh

    This WILL work, but you have to make 2 small changes to the code.

    You need a:
    2
    to ‘showposts’ => 1Thank you very much though, with these small changes the code works great!

    • Josh

      It removed my first piece for code…

      You need a:
      “<?php"
      at the start of the code

      • Josh

        Fuck. It keeps deleting the code.

        You need a:
        “less than symbol questionmark php
        at the start of the code.

        its in the screen shot but not in the sample code.

        • http://www.sridharkatakam.com Sridhar Katakam

          Thanks, fixed it.

  • http://www.adsyou.com/ شقق للبيع في الاردن

    Thank you very much though, with these small changes the code works great!

  • jeppe

    THANK YOU !
    Looking for hours for this. You showed very clearly how to do it. 

Sridhar Katakam

My name is Sridhar Katakam. I work at iThemes as support moderator and my job involves helping people build awesome sites with WordPress and iThemes Builder in particular.

Recent Posts

  • 10,000 Posts in iThemes Builder Forum and counting…
  • Natural Vision Guides Niche Review Template Now Available in WordPress
  • Public Records Niche Review Template Now Available in WordPress Format
  • Tinnitus Remedies Review Template Now Available in WordPress Format
  • Personal Dental Care Site
  • Keyconfig in Firefox
  • Independence Day Celebration Photos
  • How To Display Just the Sticky Post on Front Page in WordPress
  • Builder Child Theme – White
  • Two Simple Sites in Builder
  • WordPress 3.0
  • Wonder La Trip
  • Skin Care Niche Review Template Now Available in WordPress Format
  • PreForeclosure Niche Review Template Now Available in WordPress Format
  • Arthritis Niche Review Template Now Available in WordPress Format

Twitter Updates

Recommended Resources

  • Digital Access Pass
  • DLGuard
  • HostGator
  • iThemes
  • StudioPress
Sridhar Katakam's Blog runs on Builder by iThemes
Copyright © 2012 All Rights Reserved