While inside “the loop” in WordPress, is there an easy way to detect if a post is the most recent? A Usage Example: I want to make the first post output an H1 for the title instead of an H2. Or I want the first post to display a thumbnail image (and not the rest).
Here is some pseudocode what I’m trying to get across:
if (have_posts()):
while (have_posts()):
the_post();
the_excerpt();
if(is_most_recent()):
// do this
endif;
endwhile;
endif;
In addition to @Milo Answer (this avoids a senseless query, because we already got every needed information from the current wp_query):
Try using
get_posts()
? Codex refe.g.:
(Must be used within the Loop.)
An even easier way is to check if there is a next post. If not, we can assume this is the latest…