Advertisement
Twansparant

Sticky Custom Post Type

Jan 7th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. <?php
  2. $sticky = get_option('sticky_posts'); // Get sticky posts
  3. $totalstickies = count($sticky); // Get total of sticky posts
  4. echo $totalstickies;
  5.  
  6. // If there are sticky posts
  7. if ($sticky) {
  8.     $post_in = array($sticky[0]); // Get first sticky post id
  9.     $ignore = 0;
  10.     $suppress = false;
  11. // If there are no sticky posts
  12. } else {
  13.     $posts = get_posts(array('posts_per_page' => 1)); // Get featured posts
  14.     $post_in = array($posts[0]->ID); // Get first post id
  15.     $ignore = 1;
  16.     $suppress = true;
  17. }
  18. $args = array(
  19.     'post__in'          => $post_in, // Array of post id's
  20.     'suppress_filters'  => $suppress,
  21.     'ignore_sticky_posts'   => $ignore
  22. );
  23. $featured = new WP_Query($args); // Show newest published sticky post
  24. $total = $featured->found_posts; // Get total of queried posts
  25. echo $total; // Should output 1
  26.  
  27. if ($featured->have_posts()) :
  28.     while ($featured->have_posts()) : $featured->the_post();
  29.         $stickyid = $post->ID; ?>
  30.         <div class="sticky-featured"><?php the_post_thumbnail('large'); ?></div>
  31.     <?php endwhile;
  32. endif;
  33. wp_reset_postdata();
  34. wp_reset_query();
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement