Posted By

gd6d on 01/13/10


Tagged

wordpress duplicate sticky posts


Versions (?)

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


 / Published in: PHP
 

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

  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;?>

Report this snippet  

You need to login to post a comment.