Display categories with metadata in homepage

Hello,

How do you access a list of categories and their respective custom metadata from the homepage?
I’m trying to build something similar to http://alwaysjudging.com (each category would have a custom title & image)

1 Like

For lack of a well-formed question, this answer might or might not help you: Look into branch bundles for taxonomy kind pages.

Hello. Maybe I’ll rephrase my initial question. I have the following code inside my homepage template:

{{ range $name, $taxonomy := .Site.Taxonomies.categories }}
                <li>
                    <a href="{{ "categories/" | absLangURL }}{{ $name | urlize }}">{{ $name }}</a>
                </li>
{{ end }}

It displays the list of categories & links to their respective pages. For now, each category (taxonomy term) is identified by a name, and I’d like to have additional data attached to each term.

Let’s say I want each category to have an icon or image. I want to display in my homepage the list of categories with their respective icon/image. How can I do that?

For now, I have created a categories folder inside content, with subdirectories for each term I have. The tree looks like this:

content
—categories
——beauty
——lifestyle
——music

In each sub-folder I have an _index.md file that looks like this:

---
title: "The Look"
cover: "https://source.unsplash.com/800x600/?beauty,fashion"
---

I’m looking for a way to access the cover field/variable. Any ideas on how to do so? Is this the right thing to do in the first place?

Thanks!

Hello,

I’ve finally managed to display my list of taxonomies w/ their respective custom data directly in the homepage template.

There might be a better way to do that, but here the code I’m using for now:

    {{ $sections := where .Site.Pages "Type" "topics" }}
    {{ $sections := $sections | intersect (where .Site.Pages "Params.title" "!=" nil) }}
    
    {{ range $sections }}
        Cover image : {{ .Params.cover }} <br>
    {{ end }}

Hi, I recently went through the same problem, and found a better solution

    {{ range $name, $taxonomy := .Site.Taxonomies.tags }}

        {{ with $.Site.GetPage (printf "/tags/%s" $name) }}
            {{/*  Here we have the custom data */}}
            <li>
                <a href="{{ .Permalink }}">{{ .Params.Title }}</a>
            </li>
        {{ end }}

    {{ end }}

More details in render-a-sites-taxonomies