I will be publishing blog posts at midnight every day, and will be placing a button at the bottom of each post for readers to "mark as read". However, I only want this button to show on the latest daily post. Here's the function that I would like to create:

if post is the latest (most recent) post // do something

Any clues?



The WP_Query class orders posts based on post_date in descending order by default. In addition to this, while you're withing The Loop the WP_Query class provides the $current_post property which is the index of the post currently being displayed.

With these components, you can identify the first post with something similar to the following:

$query = new WP_Query();
if ( $query->have_posts() ) : 
    while ( $query->have_posts() ) : $query->the_post(); 
       // Display post content
       if ( 0 === $query->current_post ) {
           // Display mark as read button

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