Hugo - Difference between tags and categories
Asked Answered
P

3

7

Tags and categories are taxonomies that are automatically created by Hugo.

I do not understand what the difference is between tags and categories (besides their names). Also, do categories have the same function as organizing website pages in folders?

Pollaiuolo answered 29/11, 2021 at 4:26 Comment(0)
C
3

https://gohugo.io/content-management/taxonomies#configuring-taxonomies
Is a great resource.
But TLDR; there is no significant difference between categories and tags. They are arbitrary taxonomies.
I could make:
"fizzles: apples"
"fizzles: Bannanas"
and I would have a taxonomy page rendered for all apples and all bannanas. Note: If you are using a wordpress strict taxonomy hierarchy, you'll be confused.

To address the additional comment: The folder structure under the /content/ folder represents your site hierarchy.

I.e. /content/about-us/our-team/

will literally be:

www.yoursite.com/about-us/our-team/

Taxonomies are a different grouping - i.e. lets say I have a lot of pages, whether blog and main site or both or whatever, and I have "category: drug-rehabilitation" - then those all get categorized together/taxonomy page is created.

Hope that clarifies.

Courland answered 29/11, 2021 at 18:34 Comment(3)
Thanks for your answer! Could you clarify if there is any difference between organizing content with category taxonomies and organizing content in folders?Pollaiuolo
Hey @AkiraRorschach I believe you saw my additional notes no?Courland
Yes, the additional notes are very helpful. Thank you very much!Pollaiuolo
D
8

Disclaimer - I know:

  1. that you're referring to Hugo in particular.
  2. that this was posted quite a while ago.

However:

  1. Categories and Tags (while somehow arbitrary taxonomies, as mentioned above) pre-exist Hugo, being more related in fact to the organization of a site/blog (can you find this article you wrote a year or two ago?), UX (can a user actually find what they want in your website?) and SEO (can crawlers, search engines, etc., do so?).
  2. This is one evergreen topic, in the sense that it is more or less time/age-independent. In fact, I found this on my own research, trying to gain more accurate knowledge on the nuances thereof. And this may happen with other users in the future, too.

Now, disclaimers aside, let's deal with the task at hand.

Categories

What are categories? A quick search on Google will show you that they are compared to the chapters of a book, but hey, that highly depends on what type of book we are talking about, I feel.

So what are they then? To summarize it, they're the pillars of your site/blog. The legs of the table. The bone to the meat. In SEO-ish terms, you could say, what comes immediately after the niche.

For example, let's say you have a blog about rock and roll. Well, then rock and roll is, more or less, your niche. But what do you do in that blog? Well, you review rock and roll songs, you teach some music lessons, and you analyze lyrics. Then, maybe each different post will have a category (or more than one, although ideally not more than 3) that is either 'review', 'lesson', 'lyrics' (or you could be as specific as you want, like 'music review', 'lyrics analysis', etc.).

In other words, you wouldn't want to assign 'rock-n-roll' as your category, as that is ever-present all throughout the blog. But you also won't want 'X song lyrics analysis' cause that's only going to apply to that post (or maybe just a couple of them), right?

Tags

However, there may be patterns that you start noticing, like let's say for example, going on with the musical example, that you start noticing you tend to make a lot of lyrics analysis on ironic songs (well, I mean, the lyrics contain irony). There you have a great example for a tag: 'ironic lyrics' or if you want 'ironic songs'. Something along those lines.

An example I found particular helpful was here.

And I'd like to quote the section of the article linked that helped me the most:

For example, imagine you run a food blog. You create recipes, write reviews for appliances, and share photography tips. These main topics (recipes, reviews, photography) are your blog categories. But within each topic fall a handful of sub-topics like bread and pastry recipes, small appliance and tool reviews, and low lighting and stop-motion photography tutorials.

Well, I hope this helps anyone as much as it helped me to do this research and sharing it here.

Darmstadt answered 5/5, 2023 at 18:46 Comment(0)
C
4

This is something I've been battling with, so thought I'd share what I've learnt.

If you do not set taxonomies in your site configuration, these default values are inserted:



{
   "taxonomies": {
      "category": "categories",
      "tag": "tags"
   }
}

This seems to lead to a fairly common misconception that category and tag are hardwired into hugo, whereas they are merely suggested example names. There is a convention to use "singular": "plural". For my events listing sites, I've made my taxonomies:

{
  "taxonomies": {
    "venue": "venues",
    "artist": "artists"
  }
}

There can be any number of these, and the plural is akin to a section (ie it becomes a subdirectory in the URL). A cool thing I only recently discovered is if there is a content/<PLURAL>/<WHATEVER>/ directory with page resources, those resources can be accessed by the taxonomy templates.

Whatever plural name I picked now becomes a keyword for the frontmatter of pages which in my case are in content/events/<SOMENAME>/index.md.

An example in my case would be

{
 ...
 "artists": [
    "Wonderboom",
    "Chris Chameleon",
    "Black Cat Bones",
    "Pedro Barbosa",
    "Koos Kombuis"
  ],
  "venues": [
    "Pta - Roodeplaat"
  ],
  ...
}

Hugo automagically turns the keywords in those lists into virtual subdirectories in the URL with lowercased, hyphenated names.

In my case, joeblog.co.za/events/example/ would create virtual pages joeblog.co.za/artists/wonderboom (plus one for each other band in the list) along with joeblog.co.za/venues/pta-roodeplaat

Hugo's default is to treat "tag" pages as lists, whereas I want to treat them as leaf pages, and here found the corresponding names for their template files a bit confusing.

For joeblog.co.za/artists/ and joeblog.co.za/venues/ will happily default to layouts/_default/list.html which is all I want. In my case I want the joeblog.co.za/artists/<WHATEVER> page to be a single, but it too defaults to layouts/_default/list.html.

I discovered one way to create the equivalent of a single.html template, I need to call my templates artist.html and venue.html. Note it has to be singular, not plural.

A cool thing I only recently discovered is if there is a content/artists/wonderboom/ directory with page resources, those resources can be accessed by these templates.

If I want something other that the the default list template for the taxonomy pages, I found names like layouts/_default/artist.terms.html worked. Again, it's important for your taxonomy's singular, not plural name to be used before .terms.html.

I find Hugo's template lookup order rules very confusing, so there are umpteen other options.

Contemporary answered 8/1, 2024 at 7:55 Comment(0)
C
3

https://gohugo.io/content-management/taxonomies#configuring-taxonomies
Is a great resource.
But TLDR; there is no significant difference between categories and tags. They are arbitrary taxonomies.
I could make:
"fizzles: apples"
"fizzles: Bannanas"
and I would have a taxonomy page rendered for all apples and all bannanas. Note: If you are using a wordpress strict taxonomy hierarchy, you'll be confused.

To address the additional comment: The folder structure under the /content/ folder represents your site hierarchy.

I.e. /content/about-us/our-team/

will literally be:

www.yoursite.com/about-us/our-team/

Taxonomies are a different grouping - i.e. lets say I have a lot of pages, whether blog and main site or both or whatever, and I have "category: drug-rehabilitation" - then those all get categorized together/taxonomy page is created.

Hope that clarifies.

Courland answered 29/11, 2021 at 18:34 Comment(3)
Thanks for your answer! Could you clarify if there is any difference between organizing content with category taxonomies and organizing content in folders?Pollaiuolo
Hey @AkiraRorschach I believe you saw my additional notes no?Courland
Yes, the additional notes are very helpful. Thank you very much!Pollaiuolo

© 2022 - 2025 — McMap. All rights reserved.