Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wrabit/840d175e3b928533db8aa78f94ed592a to your computer and use it in GitHub Desktop.
Save wrabit/840d175e3b928533db8aa78f94ed592a to your computer and use it in GitHub Desktop.
Detect the first and last post in Wordpress loop
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