Skip to content

Instantly share code, notes, and snippets.

@Phlow
Last active April 30, 2024 13:30
Show Gist options
  • Save Phlow/1f27dfafdf2bbcc5c48e to your computer and use it in GitHub Desktop.
Save Phlow/1f27dfafdf2bbcc5c48e 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>
@prabhav
Copy link

prabhav commented Oct 11, 2021

Thanks so much for sharing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment