Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a theme that features a section wherein I'd like to have the single most recent post's thumbnail of a single category displayed between the header and blog sections. Something like <?php if ( has_post_thumbnail()) : ?><?php the_post_thumbnail(); ?><?php endif; ?> would work within the loop, but I'm wondering how I can make this work outside of, or separate from the loop. Ideas?

share|improve this question
add comment

1 Answer

you can always do a new wp_query to get the latest post from given category and display its thumbnail etc.. Something like

$new_query = new WP_Query( 'cat=your_category_id&showposts=1' );
if( $new_query->have_posts() ): while( $new_query->have_posts ): $new_query->the_post();

the_post_thumbnail();

endwhile;
endif;
wp_reset_query();

replace your_category_id with a proper value

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.