使用Jekyll/液体模板订购阵列 [英] Order an array with Jekyll / liquid template

查看:55
本文介绍了使用Jekyll/液体模板订购阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下操作. 我使用Jekyll创建帖子列表,并按类别(周一至周日)排序 我想按时间顺序显示它们,但杰基尔按字母顺序对它们进行显示.

I'm trying to do the following. I use Jekyll to create a list of posts, and ordertem by category (monday...sunday) I'd like to have them displayed in chronological order but Jekyll order them alphabetically.

是否可以和Jekyll一起对他进行分类?

Is it possible to sort an arry with Jekyll?

我已在邮政Yaml中添加了订单密钥,以反映星期一= 1 ...星期日= 7

I have added an order key to the post yaml to mirror monday = 1 ... sunday = 7

我正在尝试使用此顺序键对数组进行排序,但它不起作用.

I'm trying to then sort the array with this order key, bu it doesn't work.

  {% for post in posts_collate  %}
    {% capture class %} {{ post.tags | first }} {% endcapture%}
    {% capture club %} {{ post.tags | last }} {% endcapture%}

    {% if forloop.first %}
      <h2>our events</h2>
      <h3>{{ class }} & {{ club }}</h3>
      <dl>
    {% endif %}
    {% if post.rel == 'me' %}
      <dt>{{ post.category | sort: 'order' }}</dt> 
      <dd> <a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></dd>
    {% endif %}

    {% if forloop.last %}
      </dl>
    {% endif %}
  {% endfor %}

而且我在大型Google机器上找不到任何信息,所以我不确定这是可能的.

And i can't find any info in the big google machine, so i'm not sure thay it is possible.

推荐答案

只需在for语句中添加reversed

 {% for post in site.posts reversed %}
   ...
 {% endfor %}

这篇关于使用Jekyll/液体模板订购阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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