jekyll,

Dynamically list posts and tags in Jekyll

Mar 12, 2023 · 1 min read · Post a comment

As a follow-up post to Jekyll, dynamic links and JSON data, this time we are going to learn how to dynamically list posts and tags.

Prerequisites

  • Jekyll

Solution

posts

Open your HTML file where you want to list the posts URL and add the following code block:


<ul>
{% for post in site.posts %}
    <li>{{ post.url }}</li>
{% endfor %}
</ul>

tags

The same thing with tags. We will list the tag size too, which means how many posts are there using the current tag.


<ul>
{% for tag in site.tags %}
    <li>{{ tag[0] }} ({{ tag[1].size }})</li>
{% endfor %}
</ul>

Conclusion

If you get stuck at some step, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.