Do you want to check if the current post is the last post in the loop? This can help you style it differently or do whatever else you might want to do with the last post.

It’s really easy. Just use the following code:

global $wp_query;
if( ($wp_query->current_post + 1) < ($wp_query->post_count) ) {
// This is the last post in this loop.
}

This code snippet works with all types of loops even if you aren’t directly using WP_Query.

Pin It on Pinterest

Share This