As you can see yourself, creating this Loop is really very simple

Advancing Forum Analytics at China Data
Post Reply
najmus96
Posts: 11
Joined: Tue Dec 03, 2024 6:40 am

As you can see yourself, creating this Loop is really very simple

Post by najmus96 »

We start with the array declaration $argsin which we insert the specifications for the loop to be created, then we instantiate the WP_Query class by passing the parameters contained in the array and finally we proceed with the creation of a classic loop.

Instead of using the have_posts()and functions the_post()as we usually do , in this case we use them by placing in front of the instance of the newly created class, making sure that WordPress executes the Loop we just created. That is, we just have to use them as methods together with the newly created object, following the previous example we could write $loop->have_posts()or $loop->the_post().

For the rest, once inside the single article (indicated with the comment What to do armenia phone number data inside the loop ), you can safely use the functions you already know and that allow you to display the contents of an article as the_title(), the_content()without the need to specify the instance $loop.

If you were paying attention, at the end of our Loop, right after closing endif, I call the function wp_reset_query()that allows me to tell WordPress to forget about the cycle just executed and to restore the Loop to its original value. In this way, if later in our page we need to use the original cycle, we could simply execute the Loop using the functions directly have_posts()and the_post()without the risk of having compromised the correct functioning of the page itself.

Create Multiple Loops
In the course Create your first WordPress theme we discovered how simple it is to use the WP_Query class and we used it to create 3 different Loops responsible for showing articles belonging to different categories , all on the same page.

To do this all you have to do is instantiate this class three times and create as many loops:
Post Reply