First and Last Post on a Page

If you want to detect the first and last post on a page (not the entire query), you can use the code below:

if (have_posts()) : while (have_posts()) : the_post();
  if( $c == 1 ) {
  } elseif ( $c == $wp_query->post_count ) ) {
  // Rest of the code for the Loop

Leave a Reply

Your email address will not be published. Required fields are marked *