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 trialFelix lim
6,049 PointsWhy do we want to reset the loop
I am not sure about this sections, why do we reset these loops?
2 Answers
Andrew Shook
31,709 PointsDon't think of it in terms of resetting the loop, think of it in terms of resetting the call to the database that returns the values. For instance, say I want to list 5 similar articles on the side bar of a news website. But the side bar code is above the main article code. So I tell Wordpress, "hey find me 5 articles that have the same tag as this one." So Wordpress gets that from the database and I run it through a loop to print it out. Now I want to print the main article but Wordpress doesn't have that information stored in the $posts array. So now I need to tell WP to get that info, and since the main article is the default value return from the database for that page I would just "reset the loop".
Felix lim
6,049 Pointsthanks, i understood now! :)