Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $sticky = get_option('sticky_posts'); // Get sticky posts
- $totalstickies = count($sticky); // Get total of sticky posts
- echo $totalstickies;
- // If there are sticky posts
- if ($sticky) {
- $post_in = array($sticky[0]); // Get first sticky post id
- $ignore = 0;
- $suppress = false;
- // If there are no sticky posts
- } else {
- $posts = get_posts(array('posts_per_page' => 1)); // Get featured posts
- $post_in = array($posts[0]->ID); // Get first post id
- $ignore = 1;
- $suppress = true;
- }
- $args = array(
- 'post__in' => $post_in, // Array of post id's
- 'suppress_filters' => $suppress,
- 'ignore_sticky_posts' => $ignore
- );
- $featured = new WP_Query($args); // Show newest published sticky post
- $total = $featured->found_posts; // Get total of queried posts
- echo $total; // Should output 1
- if ($featured->have_posts()) :
- while ($featured->have_posts()) : $featured->the_post();
- $stickyid = $post->ID; ?>
- <div class="sticky-featured"><?php the_post_thumbnail('large'); ?></div>
- <?php endwhile;
- endif;
- wp_reset_postdata();
- wp_reset_query();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement