# Pagination gives the same result for specific page

**URL:** https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349
**Category:** support
**Tags:** pagination
**Created:** [November 8, 2022, 12:00pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349 "2022-11-08T12:00:28Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Pawel\_Lorenc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pawel_lorenc/32/18137_2.png) [@Pawel\_Lorenc](https://discourse.gohugo.io/u/Pawel_Lorenc)
#### Post date: [November 8, 2022, 12:00pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/1 "2022-11-08T12:00:28Z")

</div>

Hello,  
for the last two days I am trying to display on page paginated `regular page recursive` but unfortunately without a success.

My pages:

- /posts/
- /posts/category-a/
- /posts/category-a/page1.html
- /posts/category-b/
- /posts/category-b/page2.html
- /posts/category-b/page3.html

I would like to display paginated list of all posts in `/posts/`. Method `.RegularPagesRecursive` seems to be what I am looking for. And it works when I save the result to the variable.

```auto
{{ $pages := .RegularPagesRecursive }}
{{ printf "%v" (len .RegularPagesRecursive) }}

```

gives the appropriate results:

- 3 for `/posts/`
- 1 for `/posts/category-a/`
- 2 for `/posts/category-b/`

What DOES NOT work is pagination. Every time I paginate set of pages, I receive the same result.

```auto
 {{ $pages := .RegularPagesRecursive }}
 {{ $paginator := .Paginate $pages }}
 {{ printf "%v" $paginator.TotalNumberOfElements }}

```

gives:

- 0 for `/posts/`
- 1 for `/posts/category-a/`
- 2 for `/posts/category-b/`

If I change the rule which should give always the same number (3), again I will return the same results.

```auto
 {{ $pages := where site.RegularPages "Type" "in" site.Params.postSection }}
 {{ printf "%v" (len $pages) }}
 {{ $paginator := .Paginate $pages }}
 {{ printf "%v" $paginator.TotalNumberOfElements }}

```

gives:

- 3 0 for `/posts/`
- 3 1 for `/posts/category-a/`
- 3 2 for `/posts/category-b/`

What do I do wrong? I edit `themes/sports/layouts/_default/list.html` file.

I am aware the comment in the documentation:

```auto
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.

```

but I don’t use pagination anywhere else.

I would be very helpful for you help.

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [November 8, 2022, 12:17pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/2 "2022-11-08T12:17:55Z")

</div>

Type `tree content/posts` and paste the results here.

---

<div class="post-metadata">

### Author: ![Pawel\_Lorenc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pawel_lorenc/32/18137_2.png) [@Pawel\_Lorenc](https://discourse.gohugo.io/u/Pawel_Lorenc)
#### Post date: [November 8, 2022, 12:26pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/3 "2022-11-08T12:26:02Z")

</div>

`tree content/posts`:

```auto
content/posts
├── _index.md
├── glowna-kategoria
│ ├── _index.md
│ └── pros-and-cons-of-iphone-12.md
├── kotki
│ ├── _index.md
│ ├── with-category.md
│ └── your-new-story-url.md
└── pieski
    └── _index.md

3 directories, 7 files

```

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [November 8, 2022, 12:31pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/4 "2022-11-08T12:31:02Z")

</div>

There are only 3 _regular_ pages in your tree.

If you want to create a paginated list of _all_ regular pages in the content/posts directory:

```auto
{{ $p := where site.RegularPages "Type" "posts" }}
{{ range (.Paginate $p).Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}

```

---

<div class="post-metadata">

### Author: ![Pawel\_Lorenc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pawel_lorenc/32/18137_2.png) [@Pawel\_Lorenc](https://discourse.gohugo.io/u/Pawel_Lorenc)
#### Post date: [November 8, 2022, 12:49pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/5 "2022-11-08T12:49:06Z")

</div>

Is `{{ template "_internal/pagination.html" . }}` required? What is it file?

Having just:

```auto
{{ $p := where site.RegularPages "Type" "posts" }}
{{ range (.Paginate $p).Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}

```

gives result:

- `/posts` - blank page (which is INCORRECT)
- `/posts/glowna-kategoria` - displays 1 title (which is fine)
- `/posts/kotki` - displays 2 titles (which is fine)
- `/posts/pieski` - blank page (which is fine)

The thing is that if I change:

```auto
{{ $p := where site.RegularPages "Type" "posts" }}

```

to something which doesn’t exist e.g.:

```auto
{{ $p := where site.RegularPages "Type" "offers" }}

```

I will receive exactly the same results.

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [November 8, 2022, 12:58pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/6 "2022-11-08T12:58:41Z")

</div>

> [@Pawel\_Lorenc](#):
>
> Is `{{ template "_internal/pagination.html" . }}` required? What is it file?

[https://gohugo.io/templates/pagination/#build-the-navigation](https://gohugo.io/templates/pagination/#build-the-navigation)

Without seeing your entire project, I have no idea what you are doing wrong. So here’s a test site you can try. All “posts” are listed on the home page, paginated, 5 pages per pager.

```bash
git clone --single-branch -b hugo-forum-topic-41349 https://github.com/jmooring/hugo-testing hugo-forum-topic-41349
cd hugo-forum-topic-41349
hugo server

```

---

<div class="post-metadata">

### Author: ![Pawel\_Lorenc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pawel_lorenc/32/18137_2.png) [@Pawel\_Lorenc](https://discourse.gohugo.io/u/Pawel_Lorenc)
#### Post date: [November 8, 2022, 1:38pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/7 "2022-11-08T13:38:32Z")

</div>

Thank you for the example. It works there perfectly.

I finally found the problem. I had been looking for other `.Paginate` usage, but I didn’t notice that in `head.html` I have usage of `.Paginator` which causes the problem. I am surprised I didn’t find it before.

part of `head.html`

```auto
    {{ if .Params.meta.canonical }}
      {{ if .Paginator }}
        {{ if ne .Paginator.PageNumber 1 }}
          <link rel="canonical" href="{{ .Params.meta.canonical | strings.TrimSuffix "/" }}/page/{{ .Paginator.PageNumber }}/"/>
          <meta property="og:url" content="{{ .Params.meta.canonical | strings.TrimSuffix "/" }}/page/{{ .Paginator.PageNumber }}/"/>
        {{ else }}
          <link rel="canonical" href="{{ .Params.meta.canonical | strings.TrimSuffix "/" }}/"/>
          <meta property="og:url" content="{{ .Params.meta.canonical | strings.TrimSuffix "/" }}/"/>
        {{ end }}
      {{ else }}
        <link rel="canonical" href="{{ .Params.meta.canonical | strings.TrimSuffix "/" }}/"/>
        <meta property="og:url" content="{{ .Params.meta.canonical | strings.TrimSuffix "/" }}/"/>
      {{ end }}
    {{ end }}

```

my `baseof.html`

```auto
<!DOCTYPE html>
<html lang='{{ .Site.LanguageCode }}'>
    {{ partial "head.html" . }}
    <body class="flex m-auto min-h-screen xl:max-w-screen-xxl">
        <main class="w-full">
        {{- block "main" . }}{{- end }}
        </main>
      {{ if $.Site.Data.global.scripts }}
        {{ $.Site.Data.global.scripts.body | safeHTML }}
      {{ end }}
    </body>
</html>

```

How should I adjust my code to could in `<head></head>` set appropriate canonical urls but later in `list.html` use custom pagination?

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [November 8, 2022, 2:03pm UTC](https://discourse.gohugo.io/t/pagination-gives-the-same-result-for-specific-page/41349/8 "2022-11-08T14:03:58Z")

</div>

> [@Pawel\_Lorenc](#):
>
> How should I adjust my code to could in `<head></head>` set appropriate canonical urls but later in `list.html` use custom pagination?

[https://discourse.gohugo.io/t/get-page-number/41283/5](https://discourse.gohugo.io/t/get-page-number/41283/5)
