Forked from Phlow/jekyll-sorted-category-for-loop-alphabetical-date.liquid
Created
November 5, 2017 01:01
-
-
Save NelzkieCoder/7993c3d14f710c73f877f019f1768eb0 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.
This file contains hidden or 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 %} | |
# | |
# 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] | reversed %} | |
<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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment