Last active
October 29, 2015 14:40
-
-
Save fernandofuly/11a34211970ba50020de to your computer and use it in GitHub Desktop.
Limit Number of Sticky Posts to Show
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sticky = get_option( 'sticky_posts' ); | |
/* Sort the newest one at the top */ | |
rsort( $sticky ); | |
/* Get the 2 newest stickies (change 2 for a different number) */ | |
$sticky = array_slice( $sticky, 0, 2 ); | |
/* Query Post */ | |
$args = array( | |
'post_type' => array( 'post' ), | |
'post__in' => $sticky, | |
'ignore_sticky_posts' => 2 | |
); | |
query_posts($args); | |
?> | |
<!-- Output Html Here --> | |
<?php endif; wp_reset_query(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where should I add this code to control the number of sticky posts on homepage?