WordPress.org

Ready to get started?Download WordPress

Forums

Detecting the last post in the "The Loop" (3 posts)

  1. e-head
    Member
    Posted 9 years ago #

    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.

  2. Kafkaesqui

    Posted 9 years ago #

    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 } ?>

  3. zerolives
    Member
    Posted 9 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags