CMS Development

fair
Participante

Displaying the Month & Year on an Archive Page

resolver

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 Me gusta
1 Soluciones aceptada
KBarnes_Breck
Solución
Miembro | Partner nivel Platinum
Miembro | Partner nivel Platinum

Displaying the Month & Year on an Archive Page

resolver

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

Ver la solución en mensaje original publicado

0 Me gusta
3 Respuestas 3
KBarnes_Breck
Solución
Miembro | Partner nivel Platinum
Miembro | Partner nivel Platinum

Displaying the Month & Year on an Archive Page

resolver

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 Me gusta
Jaycee_Lewis
Administrador de la comunidad
Administrador de la comunidad

Displaying the Month & Year on an Archive Page

resolver

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


HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates.
Learn More.


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !
0 Me gusta
fair
Participante

Displaying the Month & Year on an Archive Page

resolver

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 Me gusta