Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I´m using several similar loops to loop in content from different categories into different containers. If there are no posts in category X then it shouldnt open any container at all. Same with all loops.

I´ve done this before, I open the container after "have posts" and put the divs belonging to each posts after "the post". But this loop ends differently from what I´m used to, so I dont know where to end my container divs.

http://pastebin.com/BcVEse5v

How can I end the #wrapper-extra and .thumbnails properly?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Let's throw everything, but loop out:

if ($my_query->have_posts()) {

    // open container around all posts

    while ($my_query->have_posts()) :
        $my_query->the_post();

        // output for every post

    endwhile;

    // close containers around all posts
}

As you see:

  • output of posts goes inside while loop as usual;

  • opening larger containers is between checking if we have posts and while;

  • closing larger containers should be after endwhile, but still inside if block.

share|improve this answer
    
Yes, thank you. I was confused about how I should type it in, but a friend helped me and showed that I can just close the php right after endwhile, close my divs and then start the php again. I´m not familiar with the syntax so I didnt know what to do or how to do it. Anyway, question is answered, thanks! (edit, seems I answered my own post - cant find where to move it) –  Johan Dahl Sep 14 '11 at 7:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.