Is there an if statement that can determine if a post in the loop is the last post?

For example, inside the loop could i do something like this

if lastpost { 
}
else {
}

4 s
4

if ($wp_query->current_post +1 == $wp_query->post_count) {
    // this is the last post
}

Change $wp_query to your own query variable if you made a new WP_Query object.

Leave a Comment