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

Dion Hulse (dd32) wordpress at dd32.id.au
Thu Sep 15 01:59:28 UTC 2011


You'd be right to however think, that "of course there's a post if
that template is loaded" as that assumption would be correct for the
template files you're looking at (basically anything other than
archive.php and index.php I believe).

TwentyTen/TwentyEleven however are also written to be (hopefully) of
use to new themers, IMHO It's much simpler to explain that "every page
has a loop" and make it consistently as such, not only does it help
new users get used to how to write a theme, but it also makes themes
consistently the same (Which is also a great help when you're
converting a Page template into an Archive template or similar..)

On 15 September 2011 11:52, Ptah Dunbar <wpcoredev at gmail.com> wrote:
> *<?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
>>
> _______________________________________________
> 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