19th Sep '24
/
2 comments

Posts Grouped by Month and Year in Bricks

Posts Grouped by Month and Year in Bricks

In the members-only Tutorial Requests area, a user asked:

Can you please make a tutorial how to create a post archive base on year and month, like Augustus 2024, September 2024, October 2024. like this https://changelog.announcekit.app/

This Pro tutorial provides the steps to set up nested query loops in Bricks with the outer loop looping through an array of months and years in descending order and the inner loop outputting the posts published in the current iteration of the outer query.

Step 1

Let's add code to

  • Add new "Post Months" query loop type option in the query type dropdown
  • Set up a function that should run when the "Post Months" query type is selected. This function will be set to return an array of labels (Ex.: September 2024), years (Ex.: 2024) and months (Ex.: 9 for September)
  • Add a custom function for getting the current loop object

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 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Post Views Counter Query Loop in Bricks

Post Views Counter Query Loop in Bricks

How we can output the most viewed posts in your Bricks site in a query loop.
Categories:
Related Posts by Author in Bricks

Related Posts by Author in Bricks

Querying posts on single posts by the author of the current post.
Categories:
Pro
Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Updated on 12 Dec 2023 Bricks Query Loop popup does not have a control for setting the number of posts to be output when the…
Auto Responsive Grids in Bricks

Auto Responsive Grids in Bricks

This tutorial provides the CSS that can be pasted for automatic responsive grids in Bricks Builder. Posts element Each post will get a right padding…
Pro
6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

Displaying two set of random posts, inside one query loop.
Categories:
Pro
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories:
Pro
Accordion Grid Query Loop in Bricks

Accordion Grid Query Loop in Bricks

How to set up a accordion in Bricks such that the "titles" are arranged in a grid with the full width content opening below.
Categories: