List of tags in a specific category in Jekyll

I am moving my Wordpress blog to Jekyll, which I really like. The current setup on the new site is as follows:

  • use category to distinguish between two types of posts (e.g. blog and portfolio).
  • use tag as usual

Now the problem is displaying all tags within the category , because I want to create two separate tag clouds for the two message types.

As far as I know, Liquid supports looping across all tags on this site:

 {% for tag in site.tags %} {{ tag | first }} {% endfor %} 

But I want to limit the scope to a specific category and want to do something like this:

 {% for tag in site['category'].tags %} {{ tag | first }} {% endfor %} 

Any advice would be appreciated.

+6
source share
2 answers

This seems to work for all types of filters, such as category or other front-material variables - of type type, so I can have type: article or type: video, and this seems to only get tags from one of them, if I put it in the "where" part.

 {% assign sorted_tags = site.tags | sort %} {% for tag in sorted_tags %} {% assign zz = tag[1] | where: "category", "Photoshop" | sort %} {% if zz != empty %} <li><span class="tag">{{ tag[0] }}</span> <ul> {% for p in zz %} <li><a href="{{ p.url }}">{{ p.title }}</a></li> {% endfor %} </ul> </li> {% endif %} {% endfor %} 

zz is something that you can use to filter on the first tag [0], since all it has is the tag itself, so you can filter anything else with it. tag [1] has all other things.

I originally used if zz! = Null or if zz! = "", But none of them worked.

+8
source

This will work, it will only list tags for a post of category "X". Replace X with the category name.

 {% for post in site.categories['X'] %} {% for tag in post.tags %} {{ tag }} {% endfor %} {% endfor %} 
0
source

All Articles