Display Latest Sticky Posts in WordPress

Posted by ADMIN On 4:55 AM
Assuming that you have already created a custom page template and/or already have The Loop ready, paste the following code before the loop.

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

The credit to this code goes to Justin Tadlock and partially to Nathan Rice for coming up with the array slice solution.

0 Response to "Display Latest Sticky Posts in WordPress"

Post a Comment

Google Translator

Search Box

Blog Archive

User Status

Free counters!

About Me

ADMIN
Pakistan
View my complete profile

Recent Posts

Recent Comments