Created
November 28, 2011 00:56
-
-
Save juliuzfan/1398628 to your computer and use it in GitHub Desktop.
Custom WP Query For Sticky Posts Only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Custom Query for Sticky Posts only | |
---------------------------------- | |
*/ | |
$sticky = get_option( 'sticky_posts' ); | |
$args = array( | |
'posts_per_page' => 2, // Number of sticky posts to get | |
'post__in' => $sticky, | |
'ignore_sticky_posts' => 1 | |
); | |
if ( !empty($sticky) ): | |
// has sticky posts | |
query_posts($args); | |
$stickyPosts = new WP_query(); | |
$stickyPosts->query($args); | |
if ( $stickyPosts->have_posts() ): | |
?> | |
<!-- Sticky Posts Section --> | |
<div class="sticky-posts clearfix"> | |
<!-- Intro --> | |
<div class="section-intro"><p><strong class="section-title">Sticky Articles Section</strong> <span>•</span> <em class="section-description">Some short section description</em></p></div> | |
<?php | |
while ( $stickyPosts->have_posts() ) : $stickyPosts->the_post(); | |
?> | |
<article> | |
<div class="entry-meta clearfix"><span class="author"><?php _e('by: '); the_author_posts_link(); ?></span> <span class="topic"><?php the_category( ', ' ); ?></span></div> | |
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> | |
<div class="excerpt"> | |
<figure class="alignleft"> | |
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a> | |
<figcaption><?php echo get_post(get_post_thumbnail_id())->post_excerpt; ?></figcaption> | |
</figure> | |
<?php the_excerpt();?> | |
<p><a href="<?php the_permalink()?>" title="<?php the_title_attribute( array( 'before' => __('Continue reading: '), 'after' => ' →' ) ); ?>"> <?php _e( 'Continue Reading <span class="meta-nav">→</span>'); ?></a></p> | |
</div> | |
</article> | |
<?php | |
endwhile; //end loop for sticky posts | |
endif; //have_posts() | |
?> | |
</div> <!-- end .sticky-posts --> | |
<?php | |
// RESET THE QUERY | |
wp_reset_query(); | |
endif; //has sticky posts | |
//END Custom Query for Sticky Posts only |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the post.