Listing tags in posts of specific category

Hello,

I have been trying to create a listing of tags in posts of a specific category.
This post is the closest I can find in the forums that approximates my need, but it doesn’t actually seem like the solution matches the request?

My goal is to implement a subsetted list of tags.
I do not want a list of ALL tags on the site ( I can do this fairly easily as everyone else can ).

I am trying to obtain a list of all tags associated within a specified category, over all posts in hugo. The sample output would be similar to the OPs example, aka

Food
tomatoes (3)
bread (1)
onions (4)

Music
metal (3)
rock (2)
bread (0)

etc… and then derive counts for the tags. Please notice that I put “bread” in as a tag in both categories. This could happen! The logic should first filter on the category, if there are multiple cateogories, I would like to FIRST filter for category, and then query the number of posts that have the remaining tags.

Both tags and categories are specified in individual post parameters.
I can’t figure out how to reference a returned range as the input for a second range.

  {{ range ($.Site.GetPage "taxonomyTerm" "categories").Pages }} 
	{{ if (eq .Title "food") }}	
		{{ range ($.Site.GetPage "taxonomyTerm" "tags").Pages }} 
			<li><a href="{{ .Permalink }}">{{ .Title}}</a> </li>
		{{ end }}
	{{ end }}
  {{ end }}
</ul>

The issue is the second range is referring to global site parameters,

One other side question, is this a hugo question or a golang question? Or is this the same thing? I can repost if a moderator feels this question is more approrpriate somewhere else or as a new thread.

Any help would be GREATLY appreciated, I have been trying to do this for a while!

Hi there,

I’ve moved your question to its own topic as the question in the other one has been answered.

As to your specific question, I’m not actually sure I understand what you are trying to do.

It might be easier if you had a sample project somewhere we can have a look at that shows your site content structure, and then explain the output you want.

1 Like

$ has special significance in your templates. $ is set to the starting value of . (“the dot”) by default.

thanks maiki. i have read that section in the hugo documentation but i am still unclear how to filter the site results down further by a second criteria. the first range result is straightforward and gives me all categories and all tags.

i nested the second range assuming that it would only range over the prior results but instead it ranges over the full site again. so instead of returning post tags that have category food it gives me all counts again.

Please share a repo as mentioned.

have you figured this out? im stuck on this exact same issue. i have a similar post response on the forum that was moved to its own thread but so far i have only beein pointed back to hugo documentation.

i suppose im still trying to gain better understanding of the way taxonomies are referenced and evalutated, once it clicks i presume this is an easy issue to solve.

here is what i am currently trying to modify…
the tags are always for the entire site, i cant get the range to stay constrained to the “food” criteria.

    {{ range ($.Site.GetPage "taxonomyTerm" "categories").Pages }} {{ if (eq .Title "food") }}
  • {{ .Title}}
  • {{ range $name, $taxonomy := .Site.Taxonomies.tags }} {{ $name }}
    {{ end }}
  • {{end}} {{ end }}

Hi there,

Please do not keep reviving X-year old topics with the same question. This will not get you help any faster. What will help is:

  • Read the docs. If there is a part that is unclear, ask a specific question, not just “I don’t understand the docs”.
  • Read Requesting Help
  • Post a sample repo showing what you are trying to do.
1 Like

thanks pointyfar. i think my original post is pretty descriptive and after searching both the documentation and previous posts i have found no solutions that clarify it for me, nor are the current similar posts resolved.

i think i will just figure it out myself and stay off the forums so i dont disturb you any more.
enjoy your forum base.

If you had created a repo to share, we would have figured this out very quickly. That’s how these things work.