14

我试图弄清楚如何显示一个类别(或全部)中的帖子总数。我设想如下所示,但无法完全弄清楚。我错过了文档中的某些内容吗?

{% for post in site.categories.CAT %}
    ...do some counting
{% endfor %}

posts: {% number_of_posts %}

{% for post in site.categories.CAT %}
    {{ post.title }}
{% endfor %}
4

2 回答 2

22
# all posts

{{ site.posts | size }}

# posts in one category

{{ site.categories.CAT | size }}
于 2013-04-15T14:35:26.603 回答
2
{% for post in site.categories.CAT %}
   {% capture post_count %} {{ post_count | plus: 1 }} {% endcapture %}
{% endfor %}
{{ post_count }}
于 2012-09-27T16:30:21.290 回答