0
votes

I'm trying to output tags as pages from collection items/posts, so if a user clicks on a tag it will take them to a page where I can set the layout to display all items with that specific tag.

I've been trying to use the jekyll-tagging plugin but haven't had much luck. I've tried the following.

This generates all tags within the site as links that lead to a page.

{{ site | tag_cloud }}

This generates the same as above

{{ page | tag_cloud }}

This generates all tags within the page as links but they don't output as pages and I can't figure out how to do this.

{{ page | tags }}

Am I missing something that will output the tags as pages as {{ site | tag_cloud }} does? Thanks!

1

1 Answers

0
votes

To use jekyll-tagging you need to configure it, in _config.yml add:

tag_page_layout: tag_page
tag_page_dir: tag

Then in _layouts/ folder create the file tag_page.html:

---
layout: default
---
<h2>{{ page.tag }}</h2>
<ul>
{% for post in page.posts %}
  <li><a href="{{ post.url }}">{{ post.title }}</a> ({{ post.date | date_to_string }} | Tags: {{ post | tags }})</li>
{% endfor %}
</ul>

<div id="tag-cloud">
  {{ site | tag_cloud }}
</div>

Then tag pages will be generated in the folder _site/tag and tag filters will generate links to them.