11th Mar '23
/
13 comments

Posts Grouped by Years in Bricks

This Pro tutorial provides the steps to output posts that show the most recent year in which the last post was published, then all the posts that were published in that year and continue with rest of the years in descending order in Bricks.

We shall create a custom query type called "Published Years", apply it on a query loop and place another query loop inside for showing posts that were published in the year of the parent loop iteration.

This solution gives full control to visually build the display of years (headings) and what appears for each post (date, month and linked post title in this example) using Bricks elements.

Step 1

Add the following in child theme's functions.php (w/o the opening PHP tag) 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 630 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Previous Two Posts in Bricks Query Loop

Previous Two Posts in Bricks Query Loop

This Pro tutorial shows how we can modify the parameters of a Bricks query to limit the posts to the previous two whilst cycling to…
Pro
“Truncate text to these many characters” Bricks Control

“Truncate text to these many characters” Bricks Control

Bricks provides a :<number> dynamic data tag modifier that can be used to limit the amount of text by the specified number of words. Ex.:…
Pro
Filtering ACF Repeater Bricks Query Loop by Sub Field Value

Filtering ACF Repeater Bricks Query Loop by Sub Field Value

We look into how ACF Repeater rows output by a Bricks query loop can be filtered using the bricks/query/run PHP filter.
Categories: