9

I'm trying to do the following. I use Jekyll to create a list of posts, and ordertem by category (monday...sunday) I'd like to have them displayed in chronological order but Jekyll order them alphabetically.

Is it possible to sort an arry with Jekyll?

I have added an order key to the post yaml to mirror monday = 1 ... sunday = 7

I'm trying to then sort the array with this order key, bu it doesn't work.

  {% for post in posts_collate  %}
    {% capture class %} {{ post.tags | first }} {% endcapture%}
    {% capture club %} {{ post.tags | last }} {% endcapture%}

    {% if forloop.first %}
      <h2>our events</h2>
      <h3>{{ class }} & {{ club }}</h3>
      <dl>
    {% endif %}
    {% if post.rel == 'me' %}
      <dt>{{ post.category | sort: 'order' }}</dt> 
      <dd> <a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></dd>
    {% endif %}

    {% if forloop.last %}
      </dl>
    {% endif %}
  {% endfor %}

And i can't find any info in the big google machine, so i'm not sure thay it is possible.

Yannick Schall
  • 32,601
  • 6
  • 29
  • 42

3 Answers3

4

It cannot be done without a plugin or custom function. Although, there is an ongoing effort to implement this in the next releases: https://github.com/Shopify/liquid/pull/101 and then it would look like:

{% for tag in site.tags order:ascending %} 
   ...
{% endfor %}
lzap
  • 16,417
  • 12
  • 71
  • 108
  • Hi, Is the feature already in the current build now? If no, how can I install a plugin in Shopify? Thanks – Jake Lin Aug 23 '13 at 00:31
  • Jekyll 1.4.3 depends on liquid 2.5.5 and apparently it has not been implemented yet. https://github.com/Shopify/liquid/pull/304 – Nobu Mar 21 '14 at 20:34
4

simply add reversed in the for statement

 {% for post in site.posts reversed %}
   ...
 {% endfor %}
andistuder
  • 486
  • 6
  • 6
0

Ok, not sure it is possible at all to do this kind of sorting, but i've cheated a bit (•__°)

I just renamed the post that i want to be order with a specific date like:

0000-00-01-firstpost etc...

Does it for me for now, but if there is a more clever way to do that, I'm up for it (^___^)

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
Yannick Schall
  • 32,601
  • 6
  • 29
  • 42