my tags web page https://tekki-tipps.de/en/tags/ shows the number of blog posts with certain tags. No matter which tag is clicked, all tags (tag teasers) are displayed. The whole thing worked. However, as I’m still heavily tinkering with the site at the moment, I must have introduced a bug at some point that I’ve only just noticed.
The taxonomy/list.html template is the tags web page. Clicking on a tag calls up taxonomy/tag.html. The partial tagTeaser is then called in the template. tagTeaser.html looks like this:
{{ range .Paginator.Pages }} {{ partial "articleTeaser.html" . }} {{ end }} {{ partial "paginator" . }}
I suspect the error is at the range with .Paginator.Pages. How can I fill the paginator with only the selected tag?
The online version of the website still uses Hugo version 0.85, locally I have version 0.87.0+extended darwin/amd64 with the same result.
Thank you. I overlooked the fact that there can only be one Paginator. Unfortunately, I have several possible uses for a paginator for my blog.
In the head I have added the Paginator because of the URL ./page/X and the Canonical Link. SEO - Google Note: {{ $paginator := .Paginate (where .Site.RegularPages "Section" "blog") }} {{ if .IsHome }} {{ if eq $paginator.PageNumber 1 }} <link rel="canonical" href="{{ .Permalink }}" /> {{ else }} <link rel="canonical" href="{{ .Permalink }}page/{{ $paginator.PageNumber }}/" /> {{ end }} {{ else }} <link rel="canonical" href="{{ .Permalink }}" /> {{ end }}
When I display a particular tag, I also need a paginator for the tag’s teasers. After I removed both of them, everything works now. But the reason for multiple paginators remains.
The third paginator is for the homepage and is used for the blog teasers. Is there a way to rebuild the Paginator - as a module - and then use it as Paginator-1, Paginator-2 … etc.?
Instantiate pagination conditionally. For example:
layouts/_default/baseof.html
<head>
...
...
{{ if .IsHome }}
{{ .Paginate (where site.RegularPages "Type" "post") }}
{{ else }}
{{ .Paginate .Pages}}
{{ end }}
{{ with .Paginator }}
{{ if eq .PageNumber 1 }}
...
{{ else }}
...
{{ end }}
{{ end }}
...
...
</head>
layouts/_default/home.html
{{ range .Paginator.Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}
layouts/_default/list.html
{{ range .Paginator.Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}
Notice that I placed the paginator instantiation in layouts/_default/baseof.html, not in layouts/partials/head.html. As I understand it, partials are rendered in parallel, so there’s no way to be sure that the head partial will be rendered first.
Wow, this works with the blog teasers and the tag teasers. The prerequisite is that the following entry is made as the last entry in the head area of the baseof.html:
If this is not done, the build process will tear up the head section and push everything that comes after the paginator into the body section. I haven’t got the Canonical link right yet, but I can solve that another way.
The blog teaser and tag teaser have the same source code:
{{ range .Paginator.Pages }}
{{ partial “articleTeaser.html” . }}
{{ end }}
{{ template “_internal/pagination.html” . }}
The problem at the moment is that the design is torn apart by the automatically created text "Pager 1 " in the body area. "Pager 1 " is displayed invisibly at the very top left and creates the white stripe between the green header and the menu bar. I can’t get to the automatically generated text via CSS either.
Now it works completely. It is really very helpful that you can ask questions here when you don’t know what to do. Thank you very much for the competent answer.