How to use paginate on a page, or a workaround to achieve the same end

I have a section of my site that lists out species profiles. I break those down further by taxonomic group:

  1. Mussels
  2. Mammals
  3. Reptiles

I’d like to paginate on these taxonomic pages, but they’re of type Page. According to the Docs pagination is only supported on List templates and the homepage.

Is there a workaround?

Content file

---
title: 'Southeastern Mussels'
layout: by-taxon
taxon: Mussel
tags:
    - 'Species Profile'
url: /wildlife/mussels
aliases:
    - /wildlife/mussel
    - /species/mussel
    - /species/mussels
updated: 'November 2nd, 2016'
---

Template (layout = by-taxon.ace)

{{ $profiles := where .Site.Pages "Type" "species-profile" }}
{{ $taxonContent := (index .Site.Taxonomies.tags (lower $taxon)).Pages }}
{{ $pages := intersect $profiles $taxonContent}}

{{ $paginator := .Paginate $pages 7 }}

{{ range $paginator }}
  {{ .Render "summary" }}
{{ end }}

Error

ERROR 2018/08/21 15:33:29 Error while rendering "page" in "wildlife/mussels/": template: wildlife/by-taxon.html:1:562: executing "wildlife/by-taxon.ace::main" at <.Paginate>: error calling Paginate: Paginators not supported for pages of type "page" ("Southeastern Mussels")

That pigtoe looks mighty tasty. Assuming you’ve properly set up your taxonomy you’re going to want to set up a taxonomy list page and drop your pagination logic there. Reference themes including taxonomy and terms base templates. You probably won’t need as much boilerplate as you think.

Changing my content file from <taxon>.md with a specific layout property in the front matter to _index.md turned the content file into a list page, which allows for pagination.

Thanks for sending me down the right path!

1 Like