Last active
May 24, 2018 08:53
-
-
Save wrabit/840d175e3b928533db8aa78f94ed592a to your computer and use it in GitHub Desktop.
Detect the first and last post in Wordpress loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( $wp_query->post_count == 0 ) { | |
// First post | |
} | |
if( ( $wp_query->current_post +1) == $wp_query->post_count ) { | |
// Last post | |
} | |
// detect first, even in paginated results | |
if( $wp_query->post_count == 0 && !is_paged() ) { | |
// First post | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment