i've got a static content site and I actually don't want articles display in reverse chronological order, using jekyll/liquid, what are some creative ways I can accomplish this without having to revert to reverse ordering the dates on all posts ?
With some ugly looking Liquid, it's possible to sort by something else.
Here's an example how to create a tag page, with alphabetically sorted tags.
In this example, I'm sorting the tags (and then the posts per tag are sorted in reverse chronological order - I didn't change that).
But you could use the same technique to order the posts by title or URL, for example.
EDIT:
If you just want to list your posts in forward chronological order instead of the default reverse chronological order, there's a much, much simpler solution - the reversed
keyword:
{% for post in site.posts reversed %}
<!-- whatever -->
{% endfor %}
To list your Posts by Category, you could do the following:
{% for category in site.categories %}
<h2>{{ category[0] }}</h2>
<ul class="posts">
{% for post in category[1] %}
<li><span>{{ post.date | date_to_string }}</span> » <a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
This would yield something similar to this:
Note that with this method, Posts are still listed in reverse chronological order within each category. You can see this code in action here.
A simple way of sorting by any of the front matter attributes is using sort filter.
For example, the code below will order posts by title:
{% assign sorted_posts = site.posts | sort : "title" %}
{%- for post in sorted_posts -%}
<!-- whatever -->
{%- endfor -%}
PS: also possible to combine it with reverse, like | sort : "title" | reverse
.
© 2022 - 2024 — McMap. All rights reserved.