How to adjust Jekyll post order?

Koxzi picture Koxzi · Oct 4, 2014 · Viewed 13.7k times · Source

I have started a Jekyll based blog with a theme jekyll-now. I am new to Jekyll and how it operates (especially Liquid). I understand that new posts need to be as follows: 2014-10-04-Hello-World.md. But I really don't understand how I could order these.

My first thought is that they order by date so two posts on the same date would order randomly. But is this not the case? Is there a way of ordering posts chronologically. OR at least having a post archive page?

Answer

Christian Specht picture Christian Specht · Oct 5, 2014

There is an example in the official Jekyll documentation how to create a basic post archive page:
Displaying an index of posts

Bonus: For a prettier archive page (grouped by year or year/month), see this answer.


You're right, I can't find anything in the docs where it says how the posts are ordered, but in fact Jekyll does order them chronologically, with the most recent post first (you can see this if you try the examples I linked above).

To sort them the other way (the oldest post first), you can use the reversed keyword, according to the Liquid documentation:

{% for post in site.posts reversed %}

However, I don't know how two posts on the same date are ordered, because I don't write that much posts, so I never had that problem :-)
You have to try that yourself.