Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress The Loop check if has another entry

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26292
    Cyberek
    Member

    In short:
    while in the loop:

    Code:
    have_posts()) : $my_query->the_post();?>

    I need to check if there is another loop entry, and if so add articles separator. Need to do it, so after all i’m not stuck with separator on bottom of looped posts (separator only between bosts, not after and between).
    Anybody have a clue how to check it?

    #64963

    You can call $my_query->have_posts() inside the loop to determine if there are any further posts.

    Code:
    have_posts()) : $my_query->the_post();?>

    have_posts()) : ?>



    #65480
    Cyberek
    Member

    davesgonebananas – thanks for clue, will check it with next project.

    #65942
    Cyberek
    Member

    I have checked this solution, and unfortunately it makes the loop goes infinite (after finishing first loop through posts, it starts it over and over again).
    This is the code:

    Code:

    have_posts()) : $my_query->the_post(); $i++; ?>
    ” />< have_posts()) : ?>


    #65982

    Indeed it does :-( Not to worry you can still check with this less concise code:

    Code:
    if ( $wp_query->current_post + 1 < $wp_query->post_count ) :
    // This looks like voodoo but it works, trust me :)
    endif;
    #65526
    Cyberek
    Member

    And this is working one :)

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.