Support » Plugins and Hacks » Detecting the last post in the “The Loop”

  • Is there an easy way to detect the last post on a page ?
    I’m using posts_paged, and have 6 posts displayed per page.

    I was just thinking of formatting the last post on each page a little differently.

Viewing 2 replies - 1 through 2 (of 2 total)
  • A not so pretty but effective way of doing it is to set off a count for each iteration of The Loop, then evaluate it for the correct value. That is, at the start of the loop place something like:

    <?php $atsix++; if($atsix == 6) { ?>

    Place those elements meant for your sixth post (such as giving the post div a different css class) here.

    <?php } else { ?>

    Place those elements for all the other posts here.

    <?php } ?>



    The problem with that code is, what if the last page only has 3 posts to display? Then the last post doesn’t get the correct style.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Detecting the last post in the “The Loop”’ is closed to new replies.