How can I list tags by Section?

in tags template
default and help’s ex. is list full site’s tags
if section posts only have a b c three tags
section foo have c d e three tags
in tags template
how to list section posts’s tags?

Hello qddtdlko,
It’s a bit hard to understand your question. My English isn’t the best for details.

But, to range a section:

Then you would, if I understand the question, append to a slice and then maybe use:

To ensure their was no duplicates.
There might be faster and better ways to do this, but this would work…

Their are great code examples in each of the above.

There may be a simpler way to do this, but this works.

layouts/_default/taxonomy.html

{{/* Get current taxonomy (example: tags, categories). */}}
{{ $taxonomy := .Data.Plural }}

{{/* Get sections where one or more pages has one or more terms in the current taxonomy. */}}
{{ $sections := slice }}
{{ range $term, $weightedPages := index site.Taxonomies $taxonomy }}
  {{ range $weightedPages }}
    {{ $sections = $sections | append .CurrentSection | uniq | sort }}
  {{ end }}
{{ end }}

{{/* List pages by term by section. */}}
{{ range $section := $sections }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ range $term, $weightedPages := index site.Taxonomies $taxonomy }}
    {{ $termPage := site.GetPage path.Join $taxonomy $term }}
    {{ with where $weightedPages "Section" $section.Path }}
      <h3><a href="{{ $termPage.RelPermalink }}">{{ $termPage.LinkTitle }}</a></h3>
      <ul>
        {{ range . }}
          <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
        {{end }}
      </ul>
    {{ end }}
  {{ end }}
{{ end }}

It produces something like:

Try it:

git clone --single-branch -b hugo-forum-topic-34407 https://github.com/jmooring/hugo-testing hugo-forum-topic-34407
cd hugo-forum-topic-34407
hugo server

Then visit http://localhost:1313/tags/

thanks. it close my question. just one step:
in this page how to list Books section tags but exclude Movies tags


I found it. it’s work

{{ range where .Site.Taxonomies.tags ".Page.Section" "books" }}
	{{ .Page.Title }}
{{ end }}

thanks everyone

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.