WordPress has this very cool feature called stick posts. When you make a post sticky, it shows up above your new posts, but only if your theme is set to be that way. In this tutorial we will show you a trick that will let you display latest sticky posts anywhere in your WordPress theme.
<?php /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ rsort( $sticky ); /* Get the 5 newest stickies (change 5 for a different number) */ $sticky = array_slice( $sticky, 0, 5 ); /* Query sticky posts */ query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); ?>
This code can very well be used in featured slider, or any other advanced feature that you would like to display on your site. This snippet is mostly geared toward a WordPress site that has a custom homepage or a magazine style look.