0

I have got a small blog that uses Jekyll. Now I want to add some more functionality to my post layout. I want to add this line on top of every post:

Tagged with category1, category2, ...

What is the best way to achieve this. Can someone help me with the Jekyll code that I have to add in my html file?

Tom
  • 705
  • 2
  • 9
  • 13

1 Answers1

11

It's pretty easy with Liquid filters. In your _layout/post.html template, add this line where you want the output:

Tagged with {{ page.categories | join: ', ' }}

This will join your list of categories into a comma-space delimited string. You can get fancier and link to the categories if you set up an Archive by Category index using a plugin.

Be sure that you have added categories to your individual files in _posts/ using the YAML Front Matter syntax:

---
layout: post
title: Title
categories:
- cat1
- cat2
- etc...
---
J W
  • 2,801
  • 2
  • 18
  • 22