EDIT 2024-06-18T13:20:52-07:00
This is a much simpler approach:
https://discourse.gohugo.io/t/pagination-using-pager-values-within-the-head-element/50340
Example
git clone --single-branch -b hugo-forum-topic-37643 https://github.com/jmooring/hugo-testing hugo-forum-topic-37643
cd hugo-forum-topic-37643
hugo server
To verify that we’re not clobbering our pagination parameters:
- The articles list page will show 3 articles per pager, by title
- The books list page will show 5 books per pager, by title (reversed)
- The films list page will show 7 films per pager, by date
- The quotations list page will not be paginated
layouts/_default/baseof.html
At the top of the file we define our pagination strategy, by section, for the entire site. This means that later on in the file we have access to the paginator properties (e.g., the current pager number, total number of pagers, etc.).
layouts/_default/list.html
Uses a conditional to define the page collection, mirroring the logic used in layouts/_default/baseof.html.
Comments
While this is functional, it makes pagination a “site wide” feature, instead of something you can just add when needed on any given list page. For example, with this approach, you cannot easily split an article into multiple pages using this method.
Related
https://discourse.gohugo.io/t/37494/4
https://github.com/gohugoio/hugo/issues/4507