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

3

5

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 ?

Recite answered 25/3, 2014 at 21:57 Comment(2)
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, etcExemplification
I 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.Recite
S
15

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 %}
Snippet answered 30/3, 2014 at 18:37 Comment(0)
E
1

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.

Exemplification answered 28/3, 2014 at 3:4 Comment(0)
H
0

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.

Hepatitis answered 13/5 at 9:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.