Advertisement
askwpcoach

Show WordPress Sticky Posts

Aug 25th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2. // get sticky posts from DB
  3. $sticky = get_option('sticky_posts');
  4. // check if there are any
  5. if (!empty($sticky)) {
  6.     // optional: sort the newest IDs first
  7.     rsort($sticky);
  8.     // override the query
  9.     $args = array(
  10.         'post__in' => $sticky
  11.     );
  12.     query_posts($args);
  13.     // the loop
  14.     while (have_posts()) {
  15.          the_post(); ?>
  16.     <h2><?php the_title(); ?></h2>
  17.     <?php the_content(); ?>
  18.     <div style="clear:both"></div>
  19.  <?php   } wp_reset_query();
  20. } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement