Display a sticky post only


Sponsored Links




WordPress is wonderful publishing platform, there are so many query that we can tweak it. On this chapter I will show you How to display a sticky post only in our loop. All need to do only written some code below on which area you want, example display it on sidebar.php or in header.php or footer.php. Let’s get started. Open you theme files and added this code

WordPress Sticky Post Tutorial

WordPress Sticky Post Tutorial

<?php
$sticky = get_option( ’sticky_posts’ );
query_posts( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 1, ‘orderby’ => ID, ’showposts’ => 2 ) );
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h3><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”></h3>
<?php the_excerpt(); ?>
<?php endwhile;?>
<?php endif; ?>

And done, you have create WordPress Loop and only do looping on sticky post only. There are so many solution to How to display a sticky post, like some sample from Justin Tadlock, use you creatifty and enhanced this code above.

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net


4 Responses to Display a sticky post only

  1. Pingback: wp-popular.com » Blog Archive » How To Display a sticky post only # WordPress Tricks & Tips

  2. SQL training says:

    I’m just new in using word press. I’m still learning every little bit of it. And I don’t get your code here. But I will try it and figure it out. Thank you by the way.

  3. Pingback: The Best way to replace words in your posts | Jhez3R

  4. this blog says:

    Great post. I’m a normal visitor of your blog and appreciate you taking the time to maintain the nice site. I’ll be a regular visitor for a long time.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>