Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Grouping blog posts by year
SOLVENew Contributor
12-05-2018 10:24 - edited 12-05-2018 10:49
I'm looking to create a blog template that functions in the same way to this page: https://www.familyzone.com/news
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)) %}
and
{% set yearGroup = posts|groupby(post_year) %}
But it's obviously the wrong approach.
Solved! Go to Solution.
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content