How to show posts with tag on one page?

I’m working on my personal site and want to show all posts with a specific tag on one page. For example, on the /hobbies/amateur-radio page I want to show all posts with tag amateur-radio.

https://silver-gumption-c1db40.netlify.app/hobbies/amateur-radio

I thought I might just be able to do the following:


{{ $taggedPages := index .Site.Taxonomies.tags.amateur-radio.Pages }}
<ul>
  {{ range $taggedPages }}
    <li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
  {{ end }}
</ul>

but it seems that templates may only be used in theme layouts and not in the actual HTML files themselves. Any tips on how to accomplish this or any other improvements on how I’m structuring the site would be greatly appreciated.

EDIT: Forgot to link to my repo. GitHub - cjtheham/roguefoam

Why not make β€œhobbies” a taxonomy?

site configuration

languages:
  en:
    taxonomies:
      hobby: hobbies
    languageName: English

And then in your front matter:

hobbies: ["painting", "mk2.1", "dart zone"]
1 Like

That may work…let me give that a try tonight! Thanks for the suggestion.

Thanks for the help @jmooring - I like the taxonomy method better. Follow-up question regarding layouts:

If I’m using taxonomies and want to customize the /hobbies page without affecting the files in /themes/readable, I’d make a file in /layouts/hobbies right? What page type should I be looking at in the lookup order for that /hobbies page?

config.toml

[taxonomies]
tag = 'tags'
hobby = 'hobbies'

layouts directory

layouts/
β”œβ”€β”€ _default/
β”‚   β”œβ”€β”€ baseof.html
β”‚   β”œβ”€β”€ home.html
β”‚   β”œβ”€β”€ list.html
β”‚   └── single.html
β”œβ”€β”€ hobbies/
β”‚   β”œβ”€β”€ term.html
β”‚   └── terms.html
└── tags/
    β”œβ”€β”€ term.html
    └── terms.html

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