• Hi – on the main page, my layout consists of putting each post entry in a <tr>. So i use a standard loop, and so far, so good.

    But now, I want to put another row in between posts, with another <tr>. I do this with something like this:

    while (the loop) {
    <tr>{thepost}</tr>
    <tr>other stuff</tr>
    }

    But I don’t want the extra row after the last post in the current display. I tried something like this:

    while (the loop) {
    <tr>{thepost}</tr>
    if (!empty(get_next_post())) { <tr> other stuff </tr> }
    }

    but get_next_post seems to not return empty unless i’m at the very last post (as opposed to the last post per page).

    Any ideas how to do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Maybe try something like this:

    $num_of_posts = $wp_query->post_count;
    $posts_counter = 0;
    while (the loop) {
    <tr>{thepost}</tr>
    if ( ++$posts_counter !== $num_of_posts ){<tr>other stuff</tr>}
    }

    Let me know if that works.

    Thread Starter timngdev

    (@timngdev)

    Excellent thanks! I didn’t know wp_query->post_count was paged, but in retrospect that makes sense. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to determine whether there is another post’ is closed to new replies.