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 ?
-
Is there are particular order in which you do want them to appear? For instance: alphabetical order by post.name, forward chronological, sorted by category or tags, etc– nicksuchMar 27, 2014 at 21:25
-
1I would be open to experimenting with any of those options, frankly, forward chronological order would be fine, always looking to know more about how to manipulate the behavior. thanks.– JohnMar 27, 2014 at 23:50
2 Answers
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.