I’m sorry if this seems like a stupid question, but I’m going to ask it anyway:
Per this previous post of mine, I have all of my templates in the layouts/_default folder, with all of the contents’ frontmatter referencing these. They all mostly work, but I’m having trouble creating a template to list all posts with a term in the taxonomy category.
So far, here is my code for blog-category-term.html, which is supposed to list all posts in the selected category term:
{{ define "main" }}
<h1 id="gallery-header">{{ .Title }}</h1>
{{ range .Site.Taxonomies.categories.Pages }}
<article>
{{- partial "metadata-blog-category.html" . -}}
</article>
{{ end }}
{{ end }}
(Note: metadata-blog-category.html simply parses the frontmatter in each post)
How should I change this? If you haven’t already guessed, I’m new to Hugo and trying to wrap my head around its paradigm.
True, but what I’m saying is I don’t want to use the files terms.html or taxonomy.html, I want to use my own custom templates with a unique filename (this is so every section of the site can have its own term display), and I’m wondering how I could do this.
However, I’ve already tried these templates (including yours) and they either don’t list anything or list all posts in all categories. I need it to list all posts in a specific term (which shouldn’t be hardcoded)
Here’s my new code:
{{ define "main" }}
<h1 id="gallery-header">{{ .Title }}</h1>
{{ range $key, $value := .Site.Taxonomies.categories }}
{{ range $value.Pages }}
<article>
{{- partial "metadata-blog-category.html" . -}}
</article>
{{ end }}
{{ end }}
{{ end }}
I know that this displays all terms because it’s ranging over all of the terms, but I don’t know how to make it display the posts for one term.
Cool! But, how do I replace NAME_OF_THE_TERM with the term that’s supposed to be provided when I load the page after selecting the term in the taxonomy list page?
First, to debug, in your template you need to check:
{{ .Kind }} - {{ .Section }}
Normally if you are in a proper term page the result should be:
term - categories
Then, you need to ensure in the html template that you don’t change the context (the dot .), the context can be changed if you are in a {{ with ... or in a {{ range ...
Last, according to your last message you need to have in your website config.toml:
And right away we have a problem, as adding this to the templates and loading example.com/blog/categories gives “section - blog”, while loading example.com/blog/categories/cat gives “page - blog”
Also, in my config, I have category = 'blog/categories/:slug/, as per my solution to this other problem I had. Changing “category” to “categories” does make it work, but at the same time the term pages fail to pull metadata from the _index.html files I have set up for them (these simply specify the header text and the aside text).
Awesome! This makes everything almost work perfectly, except example.com/blog/categories/ does not render anything, not even the baseof.html in my theme, while example.com/categories/ does deliver the page I’m looking for.
Luckily, I was able to fix it by adding these to /content/categories/_index.md’s frontmatter:
They are both existing and both return a blank page, even the layout baseof.html is ignored, it’s not a 404 error, a true blank html page.
Even stranger, if we create a layout taxonomy.html it will be used to render the two taxonomy pages but without the baseof.html. Only the taxonomy.html will be used.
@jmooring did you already encounter the issue I described.