How can I change the title (Title
variable in template) for a taxonomy term page?
I have tried with setting title
in a _index.md
, but I cannot get it to work.
My code is here: GitHub - mikaelstaldal/tech-blog: Mikael Ståldal's technical blog
and I want to change the title of month archive pages like /2023/10
to be something more pretty than “2023/10” as it is now.
I am trying migrate a WordPress blog to Hugo: current blog is here.
$ hugo env
hugo v0.119.0-b84644c008e0dc2c4b67bd69cccf87a41a03937e+extended linux/amd64 BuildDate=2023-09-24T15:20:17Z VendorInfo=snap:0.119.0
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.21.1"
github.com/sass/libsass="3.6.5"
github.com/webmproject/libwebp="v1.2.4"
github.com/sass/dart-sass/protocol="2.2.0"
github.com/sass/dart-sass/compiler="1.68.0"
github.com/sass/dart-sass/implementation="1.68.0"
What is full path of the _index.md that you tried to create?
ju52
3
/content/<TAXONOMY>/<TERM>/_index.md
like this sample
I tried to create /content/month/2023/10/_index.md
, but it does not work.
And I want to change the title of all terms in this taxonomy, so creating an _index.md
for each of them would be cumbersome.
ju52
6
I don’t see any config files in your repo … (or I missed it?)
Looked ia a post, you should get generated directories like
public/categories/java
etc…
then you need a content/categories/java/_index.md
file
There is a search function for the DOCs 
Read the taxonomy template doc … can help to understand Hugo better
HTH
You need to override the Ananke theme’s site-header partial.
mkdir layouts/partials
cp themes/ananke/layouts/partials/site-header.html layouts/partials/
Then replace this:
{{ .Title | default .Site.Title }}
With something like:
{{ $title := or .Title .Site.Title }}
{{ if and (eq .Kind "term") (eq .Data.Singular "month") }}
{{ $y := index (split .Data.Term "/") 0 }}
{{ $m := index (split .Data.Term "/") 1 }}
{{ $t := time.AsTime (printf "%s-%s-01" $y $m) }}
{{ $title = time.Format "Articles from Jan 2006" $t }}
{{ end }}
{{ $title }}
In the above, since $t
is a time.Time
value, you can use whatever format string you’d like.
Thanks, that works.
Would be nice to be able to override what title is passed to the theme’s template though, but maybe that’s not possible?
In this case, it’s not possible.
I am open to suggestion on better ways to achieve WordPress compatible monthly archives.
Can the published page exist only at:
https://example.org/foo/yyyy/mm/dd/title
Or do you also need:
https://example.org/foo/title
To forward to:
https://example.org/foo/yyyy/mm/dd/title
And if it forwards, which of the two URLs is canonical? I assume the latter.
I only need https://example.org/foo/yyyy/mm/dd/title
, https://example.org/foo/title
is not necessary.
(It seems like I only have https://example.org/foo/yyyy/mm/dd/title
in my current Hugo setup.)
system
Closed
14
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.