有没有办法从 site.posts 获取当前的帖子索引号?
{{ 网站.posts | size }} 是帖子的总数。 我需要的是 {{ site.posts.index }} 或 {{ page.index }}。
我试图在每个帖子页面上显示一个计数器。示例:发布 43 of 2654
最佳答案
在 for
循环中,您可以通过两种方式获取当前项目索引:
{% for post in site.posts %}{{ forloop.index }}{% endfor %}
# will print 123...
或
{% for post in site.posts %}{{ forloop.index0 }}{% endfor %}
# will print 012...
而你需要的是{{ forloop.index }}
关于ruby - 如何在 Jekyll 中检索当前的帖子索引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26073090/