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
<?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.