Blog Post Archive: Show year and number of post in brackets

What is the correct liquid syntax to show a blog post archive filter list displaying years and the number of blog posts published within that year?

2020 (14)
2019 (20)
2018 (5)

Thank you.

@Erik these docs should help:
and demo with code:

Just don’t do the second forloop (for the months) as described in this section:
…and use {{aYear.ItemsCount}} for the total count of that year.

@Adam.Wilson - Thank you. that helped!


{% component type: “module_archive”, layout: “/content/inc/”, module: “Blog Post” %}

    {% for aYear in this.years %}
  • {{}} ({{aYear.ItemsCount}})
  • {% endfor %}

I am just not sure how to link the items to filter the blog posts.

Add an anchor element with the year URL:

{% for aYear in this.years %}
<a href="/news-and-resources{{aYear.url}}">{{}} ({{aYear.ItemsCount}})</a>
{% endfor %}

But this effectively runs a search on the module, so your blog component needs to be set up with the isSearchResult: "true" parameter (if not already).

See how the Blog demo is set up here:

Thank you! All works perfectly now.

1 Like