Skip to content

Instantly share code, notes, and snippets.

@dancingmonkey
Created July 24, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancingmonkey/c5839832af8628642fdfa74bdd59f863 to your computer and use it in GitHub Desktop.
Save dancingmonkey/c5839832af8628642fdfa74bdd59f863 to your computer and use it in GitHub Desktop.
for loop collections sorted by dat
{% 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