I’ve often been asked how to show a custom loop in WordPress, for example for a specific category. And it’s no trivial matter. If you like to control what’s shown on screen, my recommendation is not to leave that job to WordPress archives, but to do it yourself, customizing the list of posts you want to show at each URL.
When should we show a custom loop?
If you have a simple blog and don’t worry much about information architecture, this isn’t the post for you. But if you want to control what you’re showing on each page, stick around.
By the way, in this post I’ll only focus on how to show the list of posts. We can show this list for a specific blog category, for example, on a specific WordPress page. This is very useful, for instance, when creating a silo architecture on your site.
If you don’t know what a silo architecture is or how to organize one in WordPress, let me know in the comments and I’ll be happy to write a post specifically on the subject.
I’ll also talk about custom post types and taxonomies. If you don’t know what they are, I also invite you to tell me in the comments below.
What exactly do we want to do?
Imagine you have a website where you write about gadgets and electronic devices. You want to split each type of device you write about on the blog into separate pages.
On the other hand, imagine you have these posts organized in a custom post type (CPT) called Devices. We’ve created a category-style taxonomy for this CPT, with three different categories:
- Computers
- Phones
- Tablets
What we want is to show the list of posts written under that CPT for each category on a different page. That is, we want a /computers/ page, a /phones/ page and a /tablets/ page.
To do this we’ll create those three blank pages and show the query loop with blocks, without touching a single line of code.
How do we show a loop on a WordPress page with blocks?
The most convenient way to do this is, indeed, with blocks. In fact, WordPress has a native Query Loop block, which is a bit limited.
So I’m going to use a plugin I’m a big fan of: GenerateBlocks. This plugin is very simple, with just four or five basic blocks, but they have loads of options and let you customize everything very well. In fact, the GenerateBlocks Pro service, created by the GeneratePress team, is built entirely on the free plugin, which you can find in the WordPress plugin directory.
To get to the point, imagine we’re on the blank Phones page, one of the categories of the Devices CPT. First we’ll insert a Container block, which gives us more control over the design.

Once the container is inserted, inside it we’ll insert the Query Loop block, but be careful not to pick the wrong one: we’ll use the GenerateBlocks one, which is blue.

When we insert it, it asks us to choose the type of layout we want. I’ll choose, for example, Two columns with featured image.

By the way, keep in mind that this tool lets us compose whatever layout we want, since it’s about nesting blocks inside one another. This is incredibly powerful because, with a little design knowledge and some experience handling blocks, you can create anything you like.
Now we need to tell this loop, or Query Loop, what we want to show. To do this, we go to the block settings (make sure you’re on the query block, not on one of the inner blocks) in the block settings panel that appears on the right in WordPress. You should see something like this:

Here we can see the list of post types we have in WordPress. Normally there will be Posts and Pages and, if we’ve already created the Devices custom post type, it will be in the list too.
In our case, I’ll select Devices, which is what I want to show, and click the Add parameter button.

The list here is long, since we can filter by loads of parameters. I won’t go through them all; if you’d like me to cover them, just let me know in the comments.
In my case, I’ll select Taxonomies, since I want to select a specific category. As you can see, besides categories and tags, there’s also device types, the taxonomy I created specifically for Devices.

When we select the Device types taxonomy, we can then choose the specific category of this taxonomy that we want to show, picking from the three types we mentioned at the start.

Since we’re on the phones page, I’ll select the Phones category.

And that’s it. When we preview the page, we’ll see that its URL is /phones/, and that we can open each of the posts about phones we’ve written.
What’s more, when we open each of these posts, we’ll see that the URL sits under /device/.

This could be improved a lot, since we could make /phones/ better organized as /devices/phones/, creating a better structure. But we’ll leave that for a post about how to organize a silo structure.
The point is that we finally have our page showing only the posts from the Devices CPT that belong to the Phones category (Device type), as you can see below.

I hope you liked it. I’d love to hear from you in the comments: tell me what you think is missing from this tutorial or what you’d like me to explain.

Leave a Reply