Juby
February 3, 2021, 6:58am
1
I’m using taxonomies as:
categories
subcategories
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.
Juby
February 19, 2021, 8:33pm
3
@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?
ju52
February 19, 2021, 10:03pm
4
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.
Juby
February 20, 2021, 3:16am
5
@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.
ju52
February 20, 2021, 7:23am
6
Please give us a repository for help.
Juby
February 27, 2021, 9:17pm
7
@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.
ju52
February 28, 2021, 2:48pm
8
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>