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?

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

Thank you.

@Erik these docs should help:
https://docs.treepl.co/component-types/module_archive
and demo with code:
https://docs.treepl.co/demo-custom-blog-2

Just don’t do the second forloop (for the months) as described in this section:
https://docs.treepl.co/component-types/module_archive#secAccessData
…and use {{aYear.ItemsCount}} for the total count of that year.

@Adam.Wilson - Thank you. that helped!

Page: https://chemneera.com/news-and-resources

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

    {% for aYear in this.years %}
  • {{aYear.name}} ({{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.name}} ({{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:
https://docs.treepl.co/demo-custom-blog-2

Thank you! All works perfectly now.

1 Like