I'd like to list all Jekyll posts in chronological order, and all posts in same category will have a same class name as I give (e.g. cate1
, cate2
, cate3
...). I've tried in many ways, still cannot figure this out. Can you help me please?
For instance, the following code can list all posts in chronological order, but all links will have the same cate1
class.
{% for post in site.posts %}
{% if site.categories.CATEGORY1 %}
<a class="cate1" href="{{ post.url }}">{{ post.title }}</a>
{% elsif site.categories.CATEGORY2 %}
<a class="cate2" href="{{ post.url }}">{{ post.title }}</a>
{% elsif site.categories.CATEGORY3 %}
<a class="cate3" href="{{ post.url }}">{{ post.title }}</a>
{% endif %}
{% endfor %}
I've also tried:
{% for post in site.posts %}
{% for post in site.categories.CATEGORY1 %}
<a class="cate1" href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}
{% for post in site.categories.CATEGORY2 %}
<a class="cate2" href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}
{% for post in site.categories.CATEGORY3 %}
<a class="cate3" href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}
{% endfor %}
This will generate each link 13 times which is my total posts amount. The link order is based on the order of categories in the loop not in chronological order.
I've also tried:
{% for post in site.posts %}
{% for CATEGORY1 in site.categories %}
<a class="cate1" href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}
{% for CATEGORY2 in site.categories %}
<a class="cate2" href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}
{% for CATEGORY3 in site.categories %}
<a class="cate3" href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}
{% endfor %}
This will generate each link 25 times. I guess this is because I have 5 categories and 5*5=25. Each link will have different class name (e.g. a_CATEGORY1_post.cate1
, a_CATEGORY1_post.cate2
, a_CATEGORY1_post.cate3
). But all posts is in chronological order.