Seeking advice on best way to proceed with pagination for section

Hi there,

I am modifying the Ink theme. I added a photo diary feature. Currently, I am using:

{{ range first 12 .Data.Pages }}
{{ if ne .Section "photos" }}

to call the first 12 pages in this section. Each photo post is a page bundle. This works well.

I would like to add pagination in this section. I plan to copy partials/pagination.html to photos/photopaginate.html, then use {{ template "photos/photopage.html" . }} in my photos/list.html file. Would that be the right approach to take? What else do I have to look out for?
.

I don’t exactly know what is a right way. But I usually did this when it comes to paginator:

{{ $pagi := .Paginate (where .Data.Pages "Section" "!=" "photos") 12 }}

But in case you only want to do paginating for first 12 photos. It will take a bit sweat:

{{ $photosPerPage := 3 }}
{{ $cond := where .Data.Pages "Section" "!=" "photos" }}
{{ $pagi := .Paginate (first 12 $cond) $photosPerPage }}

And then, apply it to 2 loops, yes two:

{{ range $pagi.Pages }}...{{ end }}
{{ range $pagi.Pagers }}
  <a href='{{ .URL | absLangURL }}'>{{ .PageNumber }}</a>
{{ end }}

Learn more @ https://gohugo.io/templates/pagination/#build-the-navigation

3 Likes

Thank you, this worked well!

You’re welcome. If my way solve your problem, could you please mark this topic as completed (I don’t know what exactly it call, let’s just tie a bow if you think it is done)?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.