I can’t seem to change PageSize from the default value of 10.
I’ve tried setting paginate = 6 in config.toml (as a top-level property), and I’ve also tried setting the limit explicitly via {{ $paginator := .Paginate (where .Pages "section" "posts") 6 }}. No matter what, {{$paginator.PageSize}} prints 6.
Pagination does seem to work, as I created 20 placeholder posts and localhost/page/2 showed with 10 posts on each page.
Here’s how I’m doing it.
{{ $paginator := .Paginate (where .Pages "section" "posts") 6 }}
{{ range $paginator.Pages.ByTitle }}
...
Any ideas? I’m running v0.81.0-59D15C97.
Are you invoking pagination more than once on the same page?
https://gohugo.io/templates/pagination/#list-paginator-pages
If you call .Paginator or .Paginate multiple times on the same page, you should ensure all the calls are identical. Once either .Paginator or .Paginate is called while generating a page, its result is cached, and any subsequent similar call will reuse the cached result. This means that any such calls which do not match the first one will not behave as written.
If you need further assistance…
Let us see your code
Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
See https://discourse.gohugo.io/t/requesting-help/9132.
@jmooring ah you’re quick! I’m only invoking pagination once on that page.
Here’s my code, if you don’t mind taking a quick look. It’s the list on the front page that I’m having issues with…markup for it is in layouts/index.html.
In your site configuration, change this:
[params]
description = "Description goes here."
baseURL = "https://example.org"
languageCode = "en-us"
enableInlineShortcodes = true
paginate = 6
To this:
title = "SAMPLE SITE"
baseURL = "https://example.org"
languageCode = "en-us"
enableInlineShortcodes = true
paginate = 6
[params]
description = "Description goes here."
You currently have baseURL, languageCode, enableInlineShortcodes, and paginate in the [params] table when they should be in the root table.
Ref: https://toml.io/en/v1.0.0#table
The top-level table, also called the root table, starts at the beginning of the document and ends just before the first table header (or EOF). Unlike other tables, it is nameless and cannot be relocated.
Wonderful, that worked! Thank you!!