Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Phlow/57eb457898e4ac4c4a20 to your computer and use it in GitHub Desktop.
Save Phlow/57eb457898e4ac4c4a20 to your computer and use it in GitHub Desktop.
Jekyll (Liquid) for loop to sort posts by category in alphabetical or date-based or similiar order.
{% comment %}
#
# Change date order by adding '| reversed'
# To sort by title or other variables use {% assign sorted_posts = category[1] | sort: 'title' %}
#
{% endcomment %}
{% assign sorted_cats = site.categories | sort %}
{% for category in sorted_cats %}
{% assign sorted_posts = category[1] | reverse %}
<h2 id="{{category[0] | uri_escape | downcase }}">{{category[0] | capitalize}}</H2>
<ul>
{% for post in sorted_posts %}
<li><a href="{{ site.url }}{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
@SeunghyunSEO
Copy link

i think "reversed" doesnt work, maybe "reverse" right

@Phlow
Copy link
Author

Phlow commented Mar 12, 2021

@SeunghyunSEO You're right! Thank you. It should be fine now! Greetings from Germany and stay healthy, mo.

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