Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list posts from the same category in Jekyll?

Tags:

jekyll

I’d like to list a fixed number of recent posts having the same category as the current post. This is what I have arrived at:

{% for category_name in page.categories limit:1 %}
    <h2>Other articles in {{ category_name }}</h2>
    <ul>
        <!-- now what? -->
    </ul>
{% endfor %}

I know about site.categories, but I don’t know how to subscript the dictionary. Obviously, site.categories.category_name is taken literally, looking for a category named “category_name”.

like image 766
zoul Avatar asked Nov 01 '13 08:11

zoul


1 Answers

{% for post in site.categories[category_name] %}
    <li>{{ post.title }}</li>
{% endfor %}
like image 116
zoul Avatar answered Sep 21 '22 06:09

zoul