11th Mar '24
/
8 comments

Posts Grouped by Years and Months in Bricks

Posts Grouped by Years and Months in Bricks

Updated on 20 Aug 2024

This Pro tutorial provides the steps to display posts (can be of any post type) organized by months within years based on the published date in Bricks.

If you want to do the same but with a date-type custom field value, refer to Events grouped by years within months based on event date custom field value.

We shall

  • write a custom PHP function that prepares and returns the data needed in the form of three arrays (sample screenshot|mirror)
  • register two custom query types - one for years and another for months (in which there are published posts)
  • set up a Years query loop and within that, a Months query loop and within that, a Posts query loop to output posts that are published in the outer two loops i.e., that iteration of year and that iteration of month.

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

Related Tutorials..

Pro
Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Updated version of the earlier Upcoming Events Grouped by ‘Month Year’ in Bricks tutorial with some improvements:
Pro
ACPT Gallery Field Query Loop in Bricks

ACPT Gallery Field Query Loop in Bricks

How we can output images from ACPT‘s Gallery field for posts as a grid using a query loop.
Categories:
Pro
Hierarchical Posts with Nested Query Loops in Bricks

Hierarchical Posts with Nested Query Loops in Bricks

Learn how to set up nested query loops in Bricks to show hierarchical posts with child posts grouped under their corresponding parent posts
Categories:
Pro
Related Posts by Taxonomy in Bricks

Related Posts by Taxonomy in Bricks

In the previous Posts Related by Current Post's Terms in Bricks tutorial, we showed how posts related to the current single post that have the…
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:
Pro
Querying Posts by ACF Date Sub Field in Bricks

Querying Posts by ACF Date Sub Field in Bricks

Updated on 17 Nov 2023. This Pro tutorial shows how we can set post__in query parameter of a query loop in Bricks to an array…
Categories:
Tags: