0

I'm using sticky posts as features posts on home page. I'd like to limit the number of sticky posts to show two the latest two. I found this code, but it makes only on latest sticky post to show.

I'd appreciate your help.

        <?php
            /* 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 2 for a different number) */
            $sticky = array_slice( $sticky, 0, 2 );

            /* Query sticky posts */
            query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
        ?>
  • What is var_dump($sticky; after the array_slice? – s_ha_dum Feb 24 '14 at 17:43
  • I don't see 'var_dump($sticky;' after 'array_slice' – Jaeeun Lee Feb 24 '14 at 17:45
  • Of course you don't see it. You need to add that code and then post the output as an edit to the question. – s_ha_dum Feb 24 '14 at 17:47
  • 1
    @Jaeeun Lee, s_ha_dum means put var_dump($sticky); right after the line $sticky = array_slice( $sticky, 0, 2 );, then save, and then tell what was the displayed value. – Shazzad Feb 24 '14 at 17:48
  • I solved it thanks to this thread link – Jaeeun Lee Feb 24 '14 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.