For the sake of this example, let’s assume we have a collection called projects
.
Here is how we can get a collection posts in ascending order on a page or index (oldest collection post first).
{% assign projects = site.projects %}
{% for project in projects %}
Sorting a Jekyll collection in reverse order (latest collection post first) is pretty straightforward in Jekyll.
{% assign projects = site.projects %}
{% for project in projects reversed %}
Now let’s look at how we can limit the number of posts from a collection and sort the result in descending order (latest collection post first). This is useful if you have a site with hundred of articles and want to create an index with the latest results in a given collection.
{% assign sorted = site.projects | sort: 'date' | reverse %}
{% for project in sorted limit: 12 %}
If you leave out | reverse
, your collection will show up oldest post first.
Note that these snippets don’t give you a pagination system.