如何在Jekyll中检索当前的职位索引号? [英] How to retrieve the current post index number in Jekyll?

查看:77
本文介绍了如何在Jekyll中检索当前的职位索引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 site.posts 获取当前的帖子索引号?

Is there a way to get the current post index number from site.posts?

{{site.posts | size}} 是帖子总数. 我需要的是类似 {{site.posts.index}} {{page.index}} 之类的东西.

{{ site.posts | size }} is the total number of posts. What I need is something like {{ site.posts.index }} or {{ page.index }}.

我正在尝试在每个帖子页面上显示一个计数器.例如:帖子2654的43

I am trying to display a counter on each post page. Example: Post 43 of 2654

推荐答案

for循环中,您可以通过两种方式获取当前商品的索引:

In a for loop you can get current item index in two ways :

{% for post in site.posts %}{{ forloop.index }}{% endfor %}
# will print 123...

{% for post in site.posts %}{{ forloop.index0 }}{% endfor %}
# will print 012...

您需要的是{{ forloop.index }}

这篇关于如何在Jekyll中检索当前的职位索引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆