【问题标题】:Total number of posts?帖子总数?
【发布时间】:2012-09-27 15:41:49
【问题描述】:

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

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

posts: {% number_of_posts %}

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

【问题讨论】:

    标签: ruby jekyll liquid


    【解决方案1】:
    # all posts
    
    {{ site.posts | size }}
    
    # posts in one category
    
    {{ site.categories.CAT | size }}
    

    【讨论】:

    • 你怎么知道的?我是红宝石和章鱼的新手。我发现很难找到任何信息,Octopress 并没有提供太多信息
    • 这不是 Ruby,而是 Liquid。
    【解决方案2】:
    {% for post in site.categories.CAT %}
       {% capture post_count %} {{ post_count | plus: 1 }} {% endcapture %}
    {% endfor %}
    {{ post_count }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 2023-01-18
      • 2011-02-17
      • 2019-12-18
      • 2011-06-01
      相关资源
      最近更新 更多