Query Loop – Related Posts
At the end of a single blog post, many sites show related content. With Query Loop, you can now dynamically pull in related articles based on categories.
1
Go to Appearance > Elements.
2
Click on Add New Element.
3
Select Block for the Element Type and click on Create.
4
You can name the Element anything you want. I named it “Related Posts”.
After naming the element, click on ‘+‘ sign to add a new block.
5
Scroll down to GenerateBlocks and click on the Query Loop block to add it.
6
Query Loop will give you multiple layout options. Select the one that best suits your blog.
7
Leave the Select post type as Posts and you can modify the Posts per page to a number of your preference.
8
Select Taxonomies from the scroll-down menu.
9
Then select Categories for Taxonomies and select Current post terms for Select Terms.
10
Then select Categories for Taxonomies and select Current post terms for Select Terms.
Afterwards, click on Add Parameter because you will be adding a second parameter to exclude the current post.
11
This time select Exclude posts from the drop-down menu.
The reason you would want to exclude the current posts is that you wouldn’t want the reader to see the current post they are already on as an option.
12
Scroll to the bottom of the page and you will see the Display Rules option. This allows you to select where you would like to see the related posts published.
Select Post and All Posts from the secondary menu.
13
On the far right-hand side, take a look near the top. You’ll find the option to switch from Block to Element. Click on Element.
Scroll down to Element Type and select Post Navigation.
Then go to Quick Hook Select and select After content container.
The Hook Name should be after_do_template_part.
Update the Priority to 1 and enable the Disable default post navigation by toggling the button.
Final Results
Click on Publish, and you are done!
Now, if you go scroll down to any of your posts, near the bottom you’ll notice related posts show up.