How to adjust Jekyll post order?
I want to document my struggle into this post so it may help other users. You need to do two changes:
- Open your posts and add weight. e.g., weight:100
- Open your html file for the menu where you want the sorted posts. For Java/J2EE menu I have java.html file at the root path of my project.
Then, add the {% assign pages_list = pages_list | sort:"weight" %}
line as shown in the below code. This will sort by weight.
{% for category in site.categories %}
{% if category[0] contains 'java' %}
<h3 id="{{ category[0] }}-ref">{{ category[0] | join: "/" }}</h3>
<ul>
{% assign pages_list = category[1] %}
{% assign pages_list = pages_list | sort:"weight" %}
{% include JB/pages_list %}
</ul>
{% endif %}
{% endfor %}
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.
Just faced the same problem and solved with this solution: https://groups.google.com/forum/#!topic/jekyll-rb/8QCIzevauSU
Add a date field to the YAML Front Matter of a post, like so:
date: 2010-09-15 14:40:45
e.g. if you have 2 posts on 2014/12/31, you can add date: 2014-12-31 00:30:00
to latest_post.md, and date: 2014-12-31 00:10:00
to older_post.md.
You can add time zone (e.g. date: 2014-12-31 00:10:00 +08:00
) if needed