Limit the number of sticky posts appearing on site

Code to limit the number of sticky posts shown in a page

/* Get all sticky posts */
$sticky = get_option( ‘sticky_posts’ );

/* Sort the stickies with the newest ones at the top */
rsort( $sticky );

/* Get the 2 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 ) );
?>

Leave a Reply