How to do sorting in Taxonomies?

I’m using taxonomies as:

  1. categories
  2. subcategories
  3. grades
    I was trying to sort subcategories as lowest to highest keeping the first two as it is. I’ve tried to use weights but it didn’t work. Can you please help me out in fixing this, please? I would appreciate it!

The image show the one i’ve right now.

@ju52 Thanks for referring that, but i’ve tried to follow that way but it didn’t work. Do you mind to show me how would you fix this issue?

you can sort it by Count.

For more help give us a repository to look in.
I have some taxonomies in my sample, bot only in one level.

@ju52 Thanks for sharing that! The structure i’m looking for is like:
Subcategories
Cursos 10 ----- 1
Cursos 11 ------ 2
Simulacros 3 ------ 4
Simulacros 5 ------ 4
Simulacros 7 ------ 4
Simulacros 9 ------ 4
Simulacros 10 ------ 4
Simulacros 11 ------ 4

My apologies as the question was quite confusing.

Please give us a repository for help.

@ju52 Here’s the repo. Because of some privacy concerns of our company i can’t share the full code instead i just shared the necessary ones here.

product listing : product-log/themes/adrian-hugo/layouts/_default/list.html
url to the repo: GitHub - juby-gif/product-log

Please feel free to go through it and let me know if you have a definite solution. Thank you very much for your help.

Hi,

there is a sort function. DOn’t know your sort favour …

try with the shown samples

Let’s say you have the following taxonomy categories:

Foo 1
Foo 2
Foo 10

Hugo does not currently have the ability to perform a natural sort (as shown above). Instead, it performs an alphabetical sort:

Foo 1
Foo 10
Foo 2

You have two options to work around this limitation.

Option A

Rename your terms by padding with leading zeros.

Foo 001
Foo 002
Foo 010

And use this template code:

<ul>
  {{ range .Site.Taxonomies.categories }}
    <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
  {{ end }}
</ul>

Option B

Add page weights to each term page.

content/categories/foo-1/_index.md:

+++
title = "Foo 1"
date = 2021-03-01T08:00:06-08:00
draft = false
weight = 1
+++

content/categories/foo-2/_index.md

+++
title = "Foo 2"
date = 2021-03-01T08:00:58-08:00
draft = false
weight = 2
+++

etc.

And use this template code:

<ul>
  {{ range sort .Site.Taxonomies.categories ".Page.Weight" }}
    <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
  {{ end }}
</ul>