Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eclectic-coding/07b0486dccf1534b159b224edbc84eeb to your computer and use it in GitHub Desktop.
Save eclectic-coding/07b0486dccf1534b159b224edbc84eeb to your computer and use it in GitHub Desktop.
This Liquid loop for Jekyll sorts a collection by date in reverse order
{% comment %}
*
* This loop loops through a collection called `collection_name`
* and sorts it by the front matter variable `date` and than filters
* the collection with `reverse` in reverse order
*
* To make it work you first have to assign the data to a new string
* called `sorted`.
*
{% endcomment %}
<ul>
{% assign sorted = site.collection_name | sort: 'date' | reverse %}
{% for item in sorted %}
<li>{{ item.title }}</li>
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment