Displaying the Month & Year on an Archive Page

I surely cannot be the only person that wants to do this, but I have not been able to find any solution.

I have a blog listing page with two filter dropdowns: Archive & Topics (Tags). Both work great, and filter the posts appropriately. I am using a modified version of the post_filter module.

I created a custom module to display my heading with some logic to change the heading based on certain criteria. After smacking my head around a bit I did manage to get the heading for my Topics (Tags) to display, but I’m not sure how to tackle the Archive.

My if/else statement in my custom module looks like this:

 {% if topic %}
 {{ page_meta.html_title|split(' | ')|last }}
 {% else %}
 {{ module.value }}
 {% endif %}

I would like for my archive page to have a heading like:

June 2024

Are there any tags I can use for this or do I need some other method? I can’t use the page title like I did for the topics, but perhaps the URL can be used? the problem is I have no idea how to actually set this up or how to even start.

Hey, @fair :waving_hand: Did you make any progress on this project? — Jaycee

Nothing yet. I may just make my own archive pages manually if I can get a blog feed to show just a specific time range.

Hi @fair

You could try extracting the date information from the URL

{% if archive_list_page %}
 {% set archive_params = request.path|split('archive')|last %}
 {% set archive_parts = archive_params|split('/') %}

 {% if archive_parts|length > 1 %}
 {% set months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] %} 
 {{ months[ archive_parts[1] - 1] ~ " " ~archive_parts[0] }}
 {% else %}
 {{ archive_parts[0] }}
 {% endif %}
{% endif %}

This would work for when you have filtered by months and years as well as just years.

I tried to use date formatting but it kept throwing an error when trying to create a date string from the url parts, so had to resort to creating an array of months and matching the index.

Hope this helps.

Karla