ThomasReggi
ThomasReggi

Reputation: 59365

Order posts by post yml front-matter number

I have each post as a company in a building and I wanna order each post (company) by suite a number set in the yml front-matter of each post. How can I do this?

Upvotes: 2

Views: 242

Answers (1)

Christian Specht
Christian Specht

Reputation: 36431

Here's another question that asked something similar, just with "regular" pages instead of blog posts.

Adapting the accepted answer to your needs (suite and posts, instead of weight and pages), you need to do the following:

Define a suite in the front-matter of each post:

---
layout: post
title: whatever
date: 2014/04/19 00:00
suite: 3
---

Display a list of all posts sorted by suite:

<ul>
{% for suite in (1..10) %}
    {% for post in site.posts %}
        {% if post.suite == suite %}
            <li><a href="{{ post.url }}">{{ post.title }}</a></li>
        {% endif %}
    {% endfor %}
{% endfor %}
</ul>

Upvotes: 1

Related Questions