Answer the question
In order to leave comments, you need to log in
How to count how many posts in a category?
Hello. I am making an Archive page, I need to display blocks: Category name (number of articles inside) and a list of articles in it.
Here is the code. How to display the number of articles in the category next to the category name?
{% for category in site.categories %}
<div id="{{ category | first | remove:' ' }}">
<h2>{{ category | first }} ({{ category | first | size }})</h2>
<ul >
{% for posts in category %}
{% for post in posts %}
{% if post.url %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
<p><time>{{ post.date | date: "%-d %B %Y" }}</time></p>
</li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
</div>
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question