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.

Example: https://github.com/markjaquith/WordPress/blob/master/wp-content/themes/twentyeleven/single.php

Isn't single.php's purpose to show single posts?

share|improve this question
    
Since your question is "why?", I don't have an answer. It works fine without the "while"; same with page.php. I notice twentyten leaves it out. –  Doug Jan 11 '12 at 18:37
    
Good catch @Doug! –  Dogbert Jan 12 '12 at 4:47

1 Answer 1

up vote 1 down vote accepted

The idea is to ensure that all the content is displayed properly. Some functions are not available outside of The Loop, as it's called, so depending on what you are doing, it may be advantageous to start the loop, even if you're relatively certain it will only be used for one post object.

share|improve this answer
1  
have_posts() just returns true or false, the_post() is what sets up the data. –  Milo Jan 11 '12 at 19:14
    
I'm aware of that, what I was trying to say, and I suppose I did a poor job of it, was that it can potentially catch errors and help for things to run more smoothly given atypical conditions. –  m0r7if3r Jan 11 '12 at 19:23
    
+1 Milo, though have_posts() will 'close' the loop (loop_end) on the final iteration. –  TheDeadMedic Jan 11 '12 at 19:25

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.