Multiple blog different categories

Hello all,
i have 2 blogs in my hugo project, so I list them using the type attribute from frontmatter
{{ $paginator := .Paginate (where .Site.Pages "Params.type" "xyz-blog") }} .

Also on the same list page, I show categories and their total count {{ range $name, $taxonomy := .Site.Taxonomies.categories }}. Now the problem is it shows categories from both the blogs since I have used .Site.

Can someone please help me with the correct syntax . Thanks in advance :slight_smile:

Do you want the terms shown limited to xyz-blog with the count representing all pages, or do you want the count limited to xyz-blog pages as well?

I want the categories in xyz-blog and count also limited to xyz-blog

    {{ range $term, $taxonomy := where .Site.Taxonomies.categories "Page.Params.type" "xyz-blog" }}
      {{ $count := len (where $taxonomy.Pages "Params.type" "xyz-blog") }}
      {{ $href := (site.GetPage (printf "categories/%s" $term)).Permalink }}
      <li><a href="{{ $href }}">{{ $term }}</a> ({{ $count }})</li>
    {{ end }}
1 Like

Great works like a charm, thanks a lot.

Also, I need to ask, so I have categories/taxonomy.html page so when I click on the above $href link it navigates to this page, and here it shows listings from both blogs. Any way out for that ??


{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Content }}
  {{ range where .Pages "Params.type" "xyz-blog" }}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  {{ end }}
{{ end }}

However, if you were on a page in “other-blog” to which the term “foo” was applied to the “categories” taxonomy, and you clicked on the “foo” link, you would not see any pages from “other-blog”. So this is a global change to what is presented for any term in the “categories” taxonomy.

What you are doing seems a bit messy. It seems like it would be easier to use a different taxonomy for the “other-blog”.

yes even I feel it is becoming a bit messy maybe will use different taxonomy, but appreciate your efforts. Thanks a ton :slight_smile:

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