Separate tag/category page for different Hugo type


Let’s say I have two different hugo types: blogs and projects

All contents can have tags.

My question:
How can I have two different category listing page, for blogs and projects.

I know hugo will auto generate pages
if we got to
but it will be for all the contents, not specific for each type

What I want:{hosting} //$hosting could be any tag{client} //$client could be any tag

Really confused right now reading the doc,
what should I do to get these page and url

I haven’t used them before, and others will probably have more relevant advice, but I believe that you are looking for taxonomies.

thanks for ur reply, I do talk about taxonomy, but related to when we have multiple content type

It’s still a taxonomy :wink:

You can create multiple taxonomies. For instance project-tags and post-tags. Add these to the frontmatter, then add layouts for them.

The ACTORS and DIRECTORS in the link by @fekete-robert are basically your project and post tags.

In the end it’s up to you not to mix them up if you don’t want to mix them between post types.

Let’s say you have two taxonomies, and three terms within each taxonomy.

Step 1 - Create Section Pages

hugo new blogs/tags/tag-a/
hugo new blogs/tags/tag-b/
hugo new blogs/tags/tag-c/
hugo new blogs/categories/category-a/
hugo new blogs/categories/category-b/
hugo new blogs/categories/category-c/
hugo new projects/tags/tag-a/
hugo new projects/tags/tag-b/
hugo new projects/tags/tag-c/
hugo new projects/categories/category-a/
hugo new projects/categories/category-b/
hugo new projects/categories/category-c/

Step 2 - Specify Layout

Add this to the frontmatter in each of the files above:

layout = "type-taxonomy-term"

Step 3 - Create Layout


{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Content }}

  {{/* Expected URL path is /type/taxonomy/term/ */}}
  {{ $pathParts := split (trim ((urls.Parse .Permalink).Path) "/") "/" }}
  {{ $type := index $pathParts 0 }}
  {{ $taxonomy := index $pathParts 1 }}
  {{ $term := index $pathParts 2 }}

  {{ $termPage := site.GetPage (printf "%s/%s" $taxonomy $term) }}

  {{ range where $termPage.Pages "Type" $type }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ end }}

{{ end }}

Step 4 - Test

1 Like