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?
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...
---
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.