Created
November 3, 2014 20:51
-
-
Save jaredkc/56f4c7551b22a86a6947 to your computer and use it in GitHub Desktop.
WordPress Featured Post
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
/** | |
* Display the most recent post in the "featured" category and | |
* keep if from showing in the default loop on the same page. | |
*/ | |
function jkc_featured_post() { | |
$featured_query = new WP_Query( array( | |
'category_name' => 'featured', | |
'posts_per_page' => '1', | |
'orderby' => 'modified' | |
) ); | |
if ( $featured_query->have_posts() ) : | |
while ( $featured_query->have_posts() ) : $featured_query->the_post(); | |
?> | |
<article id="post-<?php the_ID(); ?>" <?php post_class( 'excerpt-featured' ); ?>> | |
<?php if( has_post_thumbnail() ) : ?> | |
<a href="<?php the_permalink(); ?>" rel="bookmark"> | |
<?php the_post_thumbnail(); ?> | |
</a> | |
<?php endif; ?> | |
<?php the_title( sprintf( '<h1><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?> | |
<?php the_excerpt(); ?> | |
</article><!-- #post-## --> | |
<?php | |
endwhile; | |
// Stop this post from showing again in the default loop. | |
query_posts( array( 'post__not_in' => array( $featured_query->post->ID ) ) ); | |
wp_reset_postdata(); | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment