Grouping blog posts by year

New Contributor

I'm looking to create a blog template that functions in the same way to this page:

With blogs grouped into months grouped into years.


The issue is the news page uses a HubDB in the backend, so it functions a little differently to blogs, and I'm having a huge amount of trouble getting blog posts to group together by year.


I can print the publish year with 


{% for post in all_posts %}

{% set post_year = post.publish_date_local_time|datetimeformat('%Y') %}

{{ post_year }}

{% endfor %}




I've tried grouping them with

{% set yearGroup = posts|groupby(publish_date_local_time|truncate(4)) %}


{% set yearGroup = posts|groupby(post_year) %}

But it's obviously the wrong approach.


0 Replies

No replies on this post just yet

No one has replied to this post quite yet. Check back soon to see if someone has a solution, or submit your own reply if you know how to help! Karma is real.

Reply to post

Need help replying? Check out our Community Guidelines