WordPress.org

Ready to get started?Download WordPress

Forums

Does it really matter if its outside a div or not? (7 posts)

  1. Keyboard_Headaches
    Member
    Posted 1 year ago #

    Does it really matter if I end my loops inside of my div for the articles or not.

    <?php endwhile; ?>
    <?php endif; ?>

    I seem to get different results if I add them outside of the closing div tag versus inside the div tag

    I mean to say, If I do this

    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <article class="my-articlepost">
    <p><?php the_excerpt(); ?></p>
    
    <?php endwhile; ?>
    <?php endif; ?>
    </article>

    i get something different than if I do this

    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <article class="my-articlepost">
    <p><?php the_excerpt(); ?></p>
      </article>
    <?php endwhile; ?>
    <?php endif; ?>

    Any thoughts?
    Just so you know, this has nothing to do with my blank page post problem. :-)

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    it does matter - if you close the html tag after the loop, an dyou have more than one post, you'll soon have to deal with http://codex.wordpress.org/Validating_a_Website

  3. Keyboard_Headaches
    Member
    Posted 1 year ago #

    so my "end ifs" should be after the ending </article> tag then right?

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    if the <article> tag is after the 'while()' then the end </article> needs to be before the 'endwhile'

  5. Keyboard_Headaches
    Member
    Posted 1 year ago #

    Ah ok so it should be like this right???

    <?php endwhile; ?>
    </article>
    <?php endif; ?>

    Is this correct?
    Are there other conditions that may require something different like having both after the article tag? Or is this pretty much cut and dried?

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    Is this correct?

    no -

    you already posted the right code:

    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <article class="my-articlepost">
    <p><?php the_excerpt(); ?></p>
      </article>
    <?php endwhile; ?>
    <?php endif; ?>

    this code wraps each post correctly in an <article> tag

  7. Keyboard_Headaches
    Member
    Posted 1 year ago #

    Ah, ok gothcha, Thanks or the tip. I am a noob theme dev and sometimes the codex make me crazy, lol. My new theme is for a real estate site at http://www.entechpc.com and this is where I am having all of the issues, lol.

Topic Closed

This topic has been closed to new replies.

About this Topic