The Loop is the heart of a theme, which is what controls how your content is displayed. It is the functional connection between the MySQL database data and the HTML that is rendered in the visitor's browser. Basically anywhere a post or page is displayed, WordPress is going to use the Loop. This can be a single post or page, a loop of posts, or a sequence of loops with different display options.
Most WordPress themes feature a header, footer, and sidebar element. Figure 5-1 shows how the Loop is placed directly in the middle of these elements, creating your web site content area. This section of your web site is usually dynamic and will change as you navigate through it.
The Loop by default is used in your WordPress theme template files. Custom Loops can be created anywhere in your theme template files, as Figure 5-2 shows. Custom Loops are also used in plugins and widgets. Loops can be used anywhere inside of WordPress, but different methods exist for creating custom Loops depending on where they are used, and the potential side effects of each construction will differ.
Multiple Loops can be used throughout your theme template files. Custom Loops can be created in your header, sidebars, footer, and main content areas of your web site. There is no limit to the number of Loops that can be displayed on your web site.
The following section looks at the basic flow control of the Loop, and the WordPress template functions provided to customize the way content is displayed while being handled inside of a loop. Armed with the basics, it then goes into building custom loops based on hand-tailoring those query parameters.
Was this article helpful?