加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何在Jekyll中检索当前的帖子索引号?

发布时间:2020-12-17 01:42:38 所属栏目:百科 来源:网络整理
导读:有没有办法从site.posts获取当前的帖子索引号? {{site.posts | size}}是帖子的总数. 我需要的是{{site.posts.index}}或{{page.index}}. 我想在每个帖子页面上显示一个计数器.示例:2654年第43期 解决方法 在for循环中,您可以通过两种方式获取当前项索引: {
有没有办法从site.posts获取当前的帖子索引号?

{{site.posts | size}}是帖子的总数.
我需要的是{{site.posts.index}}或{{page.index}}.

我想在每个帖子页面上显示一个计数器.示例:2654年第43期

解决方法

在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}}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读