Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Jekyll order posts according to the Front matter

Tags:

jekyll

So if the date is in the frontmatter, Can Jekyll use this data to order posts??

Could you have multiple ways of ordering post based on whats in the frontmatter???

like image 278
st john smith Avatar asked Dec 05 '25 08:12

st john smith


2 Answers

{% assign sortedPosts = site.post | sort: 'date' %}

or

{% assign sortedPosts = site.posts | sort: 'anyFrontMatterVariable' %}

you can now loop like {% for post in sortedPosts %} ...

Note : Sorting in the loop like {% for post in site.posts | sort: 'date' %}doesn't work

like image 74
David Jacquel Avatar answered Dec 09 '25 01:12

David Jacquel


Beside date there is a way of ordering post based on whats in the YAML Front Matter

Add weight in the YAML Front Matter of your posts

post #1

---
...
weight: 1
---

post #2

---
...
weight: 2
---

Then sort them like this:

{% assign posts = site.posts | sort: 'weight' %}
{% for post in posts %}
  ..your code
{% endfor %}
like image 24
Chetabahana Avatar answered Dec 09 '25 00:12

Chetabahana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!