15th Apr '23
/
2 comments

Posts Grouped by Categories in Bricks

Update on 13 Nov 2023: There's a much simpler method here. But the following is still useful to get an understanding of how query loops in Bricks work.

This Pro tutorial provides the steps to set up nested query loops in Bricks with a Posts query inside a Terms query for showing posts grouped by their categories.

This method can be applied to show posts of any post type grouped by a corresponding taxonomy (built-in or custom), not just posts and categories.

In this example, we are showing post titles linking to their permalinks. Since we aren't using a Code element for outputting the loops we have full flexibility to visually develop the loop content by placing the various elements that Bricks builder provides.

Step 1

Copy and paste the Section from our test site using this JSON.

For the outer loop Block, the query type is set to Terms → Categories.

For the inner loop Block, the query type is set to Posts.

Step 2

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Alternating Posts from Two Post Types in Bricks

Alternating Posts from Two Post Types in Bricks

How to output posts from two seperate post types, alternating in a query loop.
Categories:
Pro
Posts Published in the Last x Days in Bricks

Posts Published in the Last x Days in Bricks

Updated on 1 Feb 2024 This Pro tutorial shows how to limit the posts output by either the Posts element or a Query Loop in…
Pro
Events grouped by months within years based on event date custom field value

Events grouped by months within years based on event date custom field value

How to output events grouped by years and months using three nested query loops in Bricks.
Categories:
Pro
Current Post’s Terms in Bricks

Current Post’s Terms in Bricks

Updated on 15 Jan 2024 This Pro tutorial provides the steps to set up a grid of terms (like categories) that the current post is…