0

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?

1 Answer 1

0

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.

1
  • 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
    Commented Sep 14, 2011 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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