Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Kent Åsvang
Kent Åsvang
18,823 Points

I is actually necessary to include the if-statement in the wordpress-loop?

Shouldn't it be sufficient to use the condition in the while loop? To me it seems redundant to first check have_posts(), and then let the while loop run as long as it is true. I'd be grateful if anyone could provide some clarity as to why we do it this way.

1 Answer

In some cases there may need to be processing before or after the posts are processed. This processing may not need to be done if there are no posts. For example, you may want to alert about new posts. This does not need to happen if there are no posts.

Kent Åsvang
Kent Åsvang
18,823 Points

Of course. Thanks for clarifying. I probably should have figured out this myself.