WordPress.org

Forums

How to check if this is last post on page? (2 posts)

  1. adrianTNT
    Member
    Posted 8 years ago #

    Hello, on my blog index page each post (article) has a bottom-border set to visually separate it from next article under it, I do not want this border to show for last post since is last one and it has page bottom line.

    How can I find if current post is last post so that I set a different CSS style for it?

    Thank you.
    - Adrian.

  2. whooami
    Member
    Posted 8 years ago #

    if you have a set number of posts on your index.php page you can do it like this, lets assume you have three (3)

    before your loop starts do this:

    <?php $postnum = 1; ?>

    Before your loop stops do this:

    <?php $postnum++; ?>

    you can do this now, this is JUST one example:

    <?php if ($postnum ==3) { ?>
    <div class="post-3" id="post-<?php the_ID(); ?>">
    <?php } else { ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <?php } ?>

    you have now assigned a different class to post #3

Topic Closed

This topic has been closed to new replies.

About this Topic