Last active
April 30, 2024 13:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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
Thanks so much for sharing this!