- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Custom monthly archive for blog posts
Apr 18, 2019 7:34 PM - edited Apr 18, 2019 7:39 PM
This issue came up when I needed to implement a monthly archive listing functionality on a customer's blog. The issue at hand is that only some archive pages list every post that was published during that month, but others do not. Those who don't usually list only 1 post. I don't think this is due to the code, since this is very inconsistent behavior, but I will add my code either way.
{% set month_day_list =[] %} {% set month_list =[] %} {% set year_list =[] %} {% set posts = blog_recent_posts('default', 250) %} <select onchange="if(this.value) window.location.href=this.value"> <option value="-1">Choose month</option> {% for post in posts %} {% set publish_month_day = post.publish_date | datetimeformat('%Y/%m') %} {% set month_day_list = month_day_list + publish_month_day %}
{% set publish_month = post.publish_date | datetimeformat('%B') %}
{% set month_list = month_list | unique + publish_month %} {% if loop.last %} {# I honestly don't understand why or how this if statement works btw #} {% for month in month_day_list|unique %} <option value="{{ group.absolute_url }}/archive/{{ month }}"> {{ month_list[loop.index - 1] | title }} {{ month | truncate(4, True, '') }} </option> {% endfor %} {% endif %} {% endfor %} </select>
I do have to be honest and say that I found this code snippet on this forum, and I can't quite wrap my head around it entirely. But since this doesn't look like a coding error (the links are generating just fine, the listing pages are not), I'm thinking this might be something I'm missing in the way HubSpot is handling blog posts?
I will not bore you with posting my listing page markup, it's the usual stuff. I'm just wondering if I'm missing something about publishing dates or whatever? All posts were imported from Wordpress, but they all have their "correct" publishing dates and they're all visible when browsing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content