CMS Development

fair
Member

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.

 

Screenshot 2024-08-09 at 1.05.22 PM.png

 

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.

 

0 Upvotes
3 Replies 3
KBarnes_Breck
Member

Displaying the Month & Year on an Archive Page

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

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Displaying the Month & Year on an Archive Page

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

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
fair
Member

Displaying the Month & Year on an Archive Page

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.

0 Upvotes