[wp-hackers] Question about use of while in 2010 loop-page and loop-single

Michael D Adams mda at blogwaffe.com
Thu Sep 15 02:42:21 UTC 2011


On Wed, Sep 14, 2011 at 5:51 PM, Claude Needham <gxxaxx at gmail.com> wrote:
> Forgive the question. But, I'd like to get some insight into why the
> Twenty-ten theme uses the following in the loop-single and loop-page.
>
> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
>
> Other themes I have looked at just use the_post() and don't include
> the while mechanism.

I think what you're asking is "Why use while when we know there can
only be one post on this view?".

I've seen plugins that hack the query to output multiple posts on
single/page views, so using while in a single/page template is a
little more flexible for people doing crazy things.

Also, always doing it the same way (which Twenty Ten doesn't) can
improve readability/reuse.

Mike


More information about the wp-hackers mailing list