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

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

概述有没有办法从site.posts获取当前的帖子索引号? {{site.posts | size}}是帖子的总数. 我需要的是{{site.posts.index}}或{{page.index}}. 我想在每个帖子页面上显示一个计数器.示例:2654年第43期 在for循环中,您可以通过两种方式获取当前项索引: {% for post in site.posts %}{{ forloop.index 有没有办法从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}}

总结

以上是内存溢出为你收集整理的ruby – 如何在Jekyll中检索当前的帖子索引号?全部内容,希望文章能够帮你解决ruby – 如何在Jekyll中检索当前的帖子索引号?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1244692.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存