List Posts of a given tag per year

Hi,

I’m currently trying to customize my tag.hbs in a way, that it is listing all posts of this tag and ordering it per year.

Here an example of what I want to achieve:

<Tag-Title>
<tag-description>

2019
- Post-Title5
- Post-Title4

2018
- Post-Title3
- Post-Title2

2017
- Post-Title1

This means I somehow need to access the date and do some comparisons… However, I’m unsure how this can be achieved.

Any hints are welcome :slight_smile:

Regards,
Christoph

Hey there @cvoigt. You aren’t the first person to ask for this Grouping posts by date?

Did you want to create a post in #Ideas and see what interest it gets? :slightly_smiling_face:

Hello

I try to do the same things
In my hbs custom template, I have this code:

{{#get "posts" filter="published_at:>='2021-01-01'+published_at:<='2021-12-31'" limit="all"}}
    {{posts.length}} posts in 2021
{{/get}}
{{#get "posts" filter="published_at:>='2020-01-01'+published_at:<='2020-12-31'" limit="all"}}
    {{posts.length}} posts in 2020
{{/get}}

It works and I can access to my posts like that. But can I put everything in a for loop with range from this year to 20 years ago?

It seems that we can create a custom helper to do that, but if I understood correctly I need to add this helper to Ghost core js files and not just in my theme

Maybe there is more simple way?