WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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

share|improve this question
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()) :

        // output for every post


    // 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


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.