Liquid markup sorting out
I am trying to display a list of all articles using fluid markup. I have this code that displays them correctly, however I want to be able to sort by date modified date (last article from the top). How can I do that?
I thought that maybe I need to create a new array with all the articles in it and then sort it, but I'm not sure how. Also note that I want to sort ALL my articles by date, not just in each folder.
{% for category in portal.solution_categories %}
{% if category.folders_count > 0 %}
{% for folder in category.folders %}
{% for article in folder.articles %}
<a href="{{ article.url }}">{{ article.title }}</a> - {{ article.modified_on | short_day_with_time }} <br>
{% endfor %}
{% endfor %}
{% endif %}
{% endfor %}
Thank!
+3
source to share
1 answer
You can use a variable to sort the list of articles and then repeat that variable.
{% for category in portal.solution_categories %}
{% if category.folders_count > 0 %}
{% for folder in category.folders %}
{% assign sorted = (folder.articles | sort:date) %}
{% for article in sorted %}
<a href="{{ article.url }}">{{ article.title }}</a> - {{ article.modified_on | short_day_with_time }} <br>
{% endfor %}
{% endfor %}
{% endif %}
{% endfor %}
+2
source to share