Coding more complex WordPress sites means you'll probably need more than one loop on certain pages. For example, a homepage with different sections and categories, or one page designs that are really trending this year.
There are a couple ways to loop in WordPress, and this is how I usually do it.
The example below features two loops. As you can see I use the rewind_posts() function on line 8. This example can be used in any WordPress template: index.php, single.php, ...
// First loop (get the last 4 posts in the "blog" category) // loop reset // Second loop (get all posts)
Why use rewind_posts()
This piece of code doesn’t use any hacks, rewind_posts() is a standard WordPress function.
You use it to “clear” a loop that has been used previously (like the first loop in our example above), allowing you to use a second loop that isn’t affected by the first loop’s results.
Now do your thing, good luck!