Display sticky post and exclude it from recent posts list in WordPress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $sticky = get_option( ’sticky_posts’ );
  3. query_posts( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 1, ‘orderby’ => ID, ’showposts’ => 2 ) );
  4. ?>
  5. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  6. <a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
  7. <?php endwhile;?>
  8.  
  9. <?php endif; ?>
  10.  
  11.  
  12. <?php $sticky = get_option(’sticky_posts’) ;
  13.  
  14. $post_to_exclude[] = $sticky[0];
  15.  
  16. $args=array(
  17. ‘caller_get_posts’=>1,
  18. ’showposts’=>2,
  19. ‘post__not_in’=> $post_to_exclude,
  20. );
  21.  
  22. query_posts($args); ?>
  23.  
  24. <h2><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a> </h2>
  25.  
  26. <?php while (have_posts()) : the_post(); ?>
  27.  
  28. <?php endwhile;?>

URL: http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.