Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are some creative ways to overcome jekyll's default 'reverse chronological order' listing?

Tags:

jekyll

liquid

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 ?

like image 673
John Avatar asked Mar 25 '14 21:03

John


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 %}
like image 147
Christian Specht Avatar answered Nov 02 '22 06:11

Christian Specht


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> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endfor %}
  </ul>
  {% endfor %}

This would yield something similar to this:

rendered Jekyll site showing category-based navigation

Note that with this method, Posts are still listed in reverse chronological order within each category. You can see this code in action here.

like image 29
nicksuch Avatar answered Nov 02 '22 04:11

nicksuch