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

Related Tutorials..

Pro
Per-Category Load More with Post Count in Bricks Builder Nested Query Loops

Per-Category Load More with Post Count in Bricks Builder Nested Query Loops

In the BricksLabs group, a user asks: Hi everyone! I'm working on a website where I need to list a large number of products on…
Pro
Mixed Post Types Grid in Bricks

Mixed Post Types Grid in Bricks

How to set up a mixed post types grid in Bricks, where you can display both standard posts and custom quote cards in alternating positions.
Categories:
Pro
ACF Post Object Query Loop inside a Posts Query Loop in Bricks

ACF Post Object Query Loop inside a Posts Query Loop in Bricks

How to loop through a CPT and within each post, output a list of related posts.
Categories:
Pro
Term Parent Slug Data Attribute in Bricks

Term Parent Slug Data Attribute in Bricks

How we can set a data attributes on a child taxonomy dynamically based on the parent taxonomy.
Categories:
Latest Featured Posts First in Bricks Query Loop (No Duplicates)

Latest Featured Posts First in Bricks Query Loop (No Duplicates)

In the Bricks Facebook group a user asks: We can use AI to help unfreeze our brains sometimes or at least have it write the…
Categories:
Pro
6 Random Featured Posts in Alphabetical Order in Bricks

6 Random Featured Posts in Alphabetical Order in Bricks

How to output x number of random posts with a specific meta value set, in Alphabetical order.
Categories: