everything you need to know


The WordPress Loop is an integral part of how your WordPress site displays content. If you want to be able to customize some parts of your site (or maybe dip your toes into WordPress development), you’ll need to know about the WordPress Loop.

Whether you’ve never heard of the WordPress Loop or you already have some basic familiarity, this post is here to get you up to speed on everything that you need to know about the WordPress Loop.

We’ll explain what it is and why being able to work with the Loop can be useful. Then, we’ll show you step-by-step how to work with the Loop in PHP templates (for classic themes) and with the Query Loop block in newer block themes.

Let’s get into it, starting right at the beginning…

What is the WordPress Loop?

The WordPress Loop is what WordPress uses to display content on your site. It’s traditionally PHP code that you can customize using template tags, though the newer WordPress block themes use the Query Loop block instead of PHP.

In more technical terms, the Loop queries your site’s database to retrieve the data for each post and then displays that data according to a template. To control this template, you can use a variety of template tags or blocks, depending on whether you’re using PHP or the Query Loop block.

For example, let’s say you have a page that lists your most recent blog posts, such as your main blog listing page:

  1. First, the Loop will check to see if any posts exist.
  2. If there are posts, it will then display the first post according to your template.
  3. Then, it will check if another post exists. If there is another post, it would “loop” the template again and show the second post according to the same template.
  4. It will continue “looping” through your posts until there are no more posts (or it hits some other limit, such as pagination rules).

Here’s a frontend example of what the Loop looks like from the Kinsta blog – each highlighted box is another iteration of the “loop”. You can see that all six boxes use the same template.

An example of the WordPress Loop showing the Kinsta blog listing page
An example of the WordPress Loop



Read more

Posted in Wordpress