I’m puzzled about taxonomy templates. I’ve read https://gohugo.io/templates/lookup-order/ I want to use a custom .html template for a category called “blog”, but not for any other categories. I’m not using any
_index.md files for front matter for categories.
In config.toml, I have
tag = “tags”
category = “categories”
author = “authors”
I have a taxonomy.html file at
/layouts/categories/ I have a
blog.htm file, but
/layouts/_default/taxonomy.html is being used for all categories.
But, if I add a
list.html or a
taxonomy.html template to
/layouts/categories/, either one will be used for all categories.
How do I use one specific template for the “blog” category and not all other categories?
You can specify a custom layout in
then have the corresponding layout file in one of the following places:
categories / blogcategorylayout . html
taxonomy / blogcategorylayout . html
category / blogcategorylayout . html
_default / blogcategorylayout . html
layout = "blog" in
/content/categories/blog/_index.md and a file in
One more question: how do I set a single.html template for blog single posts?
/layouts/categories/blog/single.html doesn’t work. And I don’t see a lookup order for a single posts in a taxonomy here: https://gohugo.io/templates/lookup-order/
That’s because there isn’t really such a thing as a taxonomy “single” page.
What does your site structure look like? Do you have your repo somewhere we can have a look at? It may be easier to help you solve your issue if you describe “what” you are trying to accomplish instead of “how” you are trying to do it. The typical scenario for example, is to have a
contents/blog/ section instead of setting
Thanks, I think that’s a better idea. I want a content type like a post, but called “blog” that has posts and a different single.html layout than my other regular posts.
So I have a folder and
title = “Blog”
type = “blog”
and then for permalinks in
config.toml I have
posts = “/:year/:month/:title/”
blog = “/:year/:month/:title/”
And for content, I assume I need folders like this?
In layouts, what do I need? A folder called
blog ? With a
list.html and a
blog = /:year/:month/:title/"
With permalinks for
blog configured like you have above, you can do the following:
If your content file has
date in the frontmatter, Hugo will know to render at
If you organise your content like:
Then you don’t need the permalinks config for
blog; Hugo will render your page at
There are pros and cons to each.
With the first option, you can just dump everything under
content/blog/ and Hugo renders the pages at the appropriate year and month subdir:
/month/) will not have a list page, ie there will not be a
yoursite.com/2020/ with all the 2020-dated posts listed. There are ways around this, but it does not happen ‘automatically’ like the
/blog/ section list page would.
With the second option, you have to maintain the year/month organisation in your content yourself, ie you have to create a
content/blog/year/month folder yourself for each month for which you have posts. The upside to this is that Hugo is able to generate list pages for you in a pretty straightforward way. (just make sure there is a
_index.md file for the sub-folders (ie the year and month sub-folders).
How you organise things is up to you and your preferences.
As for which layout files you need:
should do the trick.
I have some more complicated examples in this post I wrote. But I don’t know if that is just information overload at this point
Thanks! That makes sense. I went with #2, as I want to make content easier to manage in year/month folders. But I don’t care about lists for each year and month, so I don’t need the _index.md files in each. And I didn’t realize I didn’t need permalinks in toml if I had my own directory structure.
The list and single files work in /layouts/blog/.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.