Hugo paginator add pages?

Hello guys,
I just wanted to build a little pagination for my blog. Currently hugo will load all markdown files from the $ directory. For the “Snipppets” section the pagination works fine.

The structure is like:

But for the “Hub” section I got some “series posts” and the paginator doesn’t understand that the pages are in subdirectorys.

The structure is like:

The code for the pagination:

{{ $pag := $.Paginator }}
{{ $pag }}
{{ if gt $pag.TotalPages 1 }}

<div class="section-xs">
	<div class="container" style="text-align: center;">
		<div class="pagination-wrapper margin-0">
			<div class="pagination">
				<a class="prev page-numbers" {{ if $pag.HasPrev }}href="{{ $pag.Prev.URL }}"{{ end }}><<</a>

				{{ range $pag.Pagers }}
					{{ if eq . $pag }}
					<span aria-current="page" class="page-numbers current">{{ .PageNumber }} </span>
					{{ else }}
					<a class="page-numbers" href="/snippets/page/{{ .PageNumber }}">{{ .PageNumber }}</a>
					{{ end }}
				{{ end }}

				<a class="next page-numbers" {{ if $pag.HasNext }}href="{{ $pag.Next.URL }}"{{ end }}>>></a>
{{ end }}

Can I count/add some pages to the paginator with a {{ range }} function or is the paginator also able to range also through subdirectorys? In the documentation I can’t find something usefull.


What you want to look into is the .Paginate method – which allows to paginate any page collection you want, e.g.:

{{ $pag := $.Paginate site.RegularPages }}

{{ $paginator := .Paginate (where .Site.RegularPages “Section” “hub”) }}
I tried it with something like this, but it also shows the same.

Then you need to check if you have .Paginate (or .Paginator) called earlier in the template(s), as the paginator is static (1 per page and the first will win).