Advertisement
juanda_escobar

How to display the first 5 sticky posts in WP?

May 26th, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. <?php
  2. $stickies = get_option( 'sticky_posts' );
  3. rsort( $stickies );
  4. $stickies = array_slice( $stickies, 0, 5 );
  5.  
  6. $argmts = array(
  7.     'post__in'      => $stickies,
  8.     'caller_get_posts' => 1,
  9. );
  10.  
  11. $entradas_slider = new WP_Query($argmts);
  12.  
  13. if ( $entradas_slider->have_posts() ) : $entradas_slider->the_post();
  14.  
  15.     ... the markup ...
  16.  
  17. else :
  18.     // If there are no sticky posts, show this instead.
  19.     include 'dummy_sldr.php';      
  20. endif;
  21. // Reset Post Data
  22. wp_reset_postdata();
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement