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

Ptah Dunbar wpcoredev at gmail.com
Thu Sep 15 01:52:55 UTC 2011


*<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>*

Basically twentyten checks to see if a post actually exists where as using
just the_post(), you're making an assumption that a post already exists and
it just gets straight to the point (setting up the post data globals).

The preferred way is of course actually checking to make sure a post exists
before calling the_post() to avoid any crazy, random errors that may arise.

Hope that helps!

@ptahdunbar

On Wed, Sep 14, 2011 at 8: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 have a natural respect for the Twenty-Ten. So, I'm assuming there is
> some behind the scene advantage to this approach.
>
> I know this is probably glaringly obvious. But, could someone either
> drop a hint, or point to a resource that would give me some insight
> into this.
>
> Thanks in advance,
> Claude Needham
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list