I want to create a category index that simply creates a list of the categories in the site and a link to each category's index, as generated by the category index generator.
---
layout: default
title: "Categories"
---
<div id="category-index" class="container">
<ul id="categories">
{% for category in site.categories %}
<li><a href="/{{category}}/">{{ category }}</a></li>
{% endfor %}
</ul>
</div>
but this give the entire array of posts. I just want the category name. I've tried category.key
, category.name
, and category.title
, but I just do not seem to be able to get just that name.
I am also hoping to do the same with site.tags, assuming there is a similar answer.
You are looking at the correct site.categories
, but for the name, you must reference the first object in the array as category[0]
.
Regarding tag lists, you may want to look at this helper class.
A more elegant way to code this, using the Liquid templating engine's filter, would be:
{% for category in site.categories %}
{{ category | first }}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With