WordPress.org

Ready to get started?Download WordPress

Forums

What do endwhile; and endif; do in the loop? (3 posts)

  1. Jones Elizabeth
    Member
    Posted 1 year ago #

    Hi, I have just started to learn about wordpress development. What do endwhile; and endif; do in the loop?

    <?php (have_posts () ) : while (have_posts () ) : the_post (); ?>
    
    And ends with this:
    
    <?php endwhile; else: ?>
    <p> some error message or similar . </p>
    <?php endif; ?>

    In the examples I've looked through, endwhile; and endif; are always near the end of the loop. But what does endwhile specifically do? And what does endif specifically do?

    Many thanks for reading this :)

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    They close the loops. Anything outside of those loops (closed) will not be repeated within that loop.

  3. Jones Elizabeth
    Member
    Posted 1 year ago #

    Thank-you :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags