Hello!
I would like to sort my blog articles in descending order, that is, in order of oldest posting date.
I edited bolog-listings module file as below, but they don’t work.
{% for c in contents |sort(attribute='publish_time') %}
{% if loop.index0 < remaining_cols %}
{# initial columns #}
{% do initial_posts.append(c) %}
{% else %}
{# regular columns #}
{% do remaining_posts.append(c) %}
{% endif %}
{% endfor %}
{% for c in contents |reverse %}
{% if loop.index0 < remaining_cols %}
{# initial columns #}
{% do initial_posts.append(c) %}
{% else %}
{# regular columns #}
{% do remaining_posts.append(c) %}
{% endif %}
{% endfor %}
How should I edit the module file?
thanks in advance.
Thank you for answering.
I tried the code below first, but the ascending order remained the same.
Please let me know if there is anything else that needs to be corrected.
{% for c in contents|sort(True, False, "publish_date") %}
{% if loop.index0 < remaining_cols %}
{# initial columns #}
{% do initial_posts.append(c) %}
{% else %}
{# regular columns #}
{% do remaining_posts.append(c) %}
{% endif %}
{% endfor %}
For the reverse, try removing the space before the |Reverse. This will only reverse the order of posts displayed on the current page. If you have pagination, then it won’t sort through the other pages.
{% for c in contents|reverse %}
<article class="index-article">
<div class="blog-listing">
{% for tag in post.tag_list %}
{% if loop.index == 1 %}
<h2>{{ tag.name }}</h2>
{% endif %}
{% endfor %}
</div>
<div class="Listing-content">
<p class="title"><a href="{{post.absolute_url}}">{{post.name}}</a></p>
<p class="exerpt">{{ post.meta_description }}</p>
</div>
</article>
{% endfor %}