0
votes

In my jekyll site I have 3 categories in a post. I want to show badges for each category and their post count. I used

{% for category in page.categories %}
{% unless category == 'index'%}
<a href="/cat/{{category}}">{{category}}{{category.size}}</a>
{% endunless %}
{% endfor %}

in post layout. This works, but post count shows wrong number. I also tried without unless statement but not works.

1

1 Answers

0
votes

{{category.size}} counts the number of letters in current category name.

If you want the number of posts in this category, the correct syntax is :

{{ site.categories[category].size }}