# Hugo paginator range for subdirectories?

**URL:** <https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957>\
**Category:** support\
**Tags:** pagination\
**Created:** [March 12, 2020, 7:46am UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957 "2020-03-12T07:46:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OjunbamO](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@OjunbamO](https://discourse.gohugo.io/u/OjunbamO)\
**Post date:** [March 12, 2020, 7:46am UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957/1 "2020-03-12T07:46:28Z")

</div>

Hello guys,  
my plan is to show all posts under a specific sub-website called /posts there should be listed all posts from “content/posts/_subdirectory_/_post1_/\_index.md”. The reason for the subdirectory is to have a knowledgebase more organized with “series”. I have a list which works fine for my Problem:

```auto
{{ range (where .Site.RegularPages "Section" "posts") }}
   <a href="{{.Permalink}}">{{- .Title -}}</a>
{{ end }}

```

But if i use this list 1. i can’t view all pages of a specific subdirectory for example on the site: “content/posts/_subdirectory_/” and 2. my list-pagination to split the posts up is also broken.

If i just range the paginator pages only single posts will be displayed, so the subdirectory listing works fine but not for the /posts overview, there will be nothing:

```auto
{{ range .Paginator.Pages }}

```

Do you know any way to include websites of a sub-sub-directory to the pagination or know a workaround which also works with the pagination?

Regards  
OjunbamO

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 12, 2020, 10:46am UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957/2 "2020-03-12T10:46:10Z")

</div>

I’m not sure I understand the problem, but:

- I assume you know about the `.Paginate` method? You can do `.Paginate (where .Site.RegularPages "Section" "posts") `
- Also, if you do `$post1.Pages` or `$post1.RegularPages` you will get only the pages in that section.

There is an open issue about adding some recursive helper methods that I hope I or someone else will get to soon, which would enable to rewrite:

```auto
{{ $posts := (where .Site.RegularPages "Section" "posts") }}

```

To

```auto
{{ $posts := (site.GetPage "post").RegularPagesRecursive }}

```

Etc.

---

<div class="post-metadata">

**Author:** ![OjunbamO](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@OjunbamO](https://discourse.gohugo.io/u/OjunbamO)\
**Post date:** [March 12, 2020, 3:29pm UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957/3 "2020-03-12T15:29:01Z")

</div>

First thanks for you’re answer.  
I tried to use .Paginate but it always results in an error.

summarized:  
I just need to iterate over all pages in a specific subdirectory with .Paginate and list all posts of the “Sub-Sub directorys”.

First I was using ` {{ range .Paginator.Pages }}` but on the /posts list section it showed nothing. For the list /posts/_whateverseries_ it worked very well.

Regards

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 12, 2020, 3:32pm UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957/4 "2020-03-12T15:32:48Z")

</div>

> [@OjunbamO](#):
>
> I tried to use .Paginate but it always results in an error.

So, instead of looking for non-existent solutions, you should get the working one working. What is the error?

---

<div class="post-metadata">

**Author:** ![OjunbamO](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@OjunbamO](https://discourse.gohugo.io/u/OjunbamO)\
**Post date:** [March 12, 2020, 3:53pm UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957/5 "2020-03-12T15:53:11Z")

</div>

If I try to use your solution, it just says that RegularPagesRecursive isn’t existed like. Also not existend in the docs.

```auto
render of "section" failed: "layouts/_default/list.html:103:31": execute of template failed: template: _default/list.html:103:31: executing "main" at <"hub">: can't evaluate field RegularPagesRecursive in type page.Page
render of "section" failed: "layouts/_default/list.html:103:31": execute of template failed: template: _default/list.html:103:31: executing "main" at <"hub">: can't evaluate field RegularPagesRecursive in type page.Page
Rebuild failed:

Failed to render pages: render of "section" failed: "layouts/_default/list.html:103:31": execute of template failed: template: _default/list.html:103:31: executing "main" at <"hub">: can't evaluate field RegularPagesRecursive in type page.Page

```

and just `{{ .Paginate.Pages }}` says:

```auto
render of "section" failed: "layouts/_default/list.html:103:16": execute of template failed: template: _default/list.html:103:16: executing "main" at <.Paginate.Pages>: wrong number of args for Paginate: want at least 1 got 0
render of "section" failed: "layouts/_default/list.html:103:16": execute of template failed: template: _default/list.html:103:16: executing "main" at <.Paginate.Pages>: wrong number of args for Paginate: want at least 1 got 0
Rebuild failed:

Failed to render pages: render of "section" failed: "layouts/_default/list.html:103:16": execute of template failed: template: _default/list.html:103:16: executing "main" at <.Paginate.Pages>: wrong number of args for Paginate: want at least 1 got 0

```

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 12, 2020, 4:51pm UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957/6 "2020-03-12T16:51:39Z")

</div>

> [@OjunbamO](#):
>
> If I try to use your solution, it just says that RegularPagesRecursive isn’t existed like. Also not existend in the docs.

OK. That was me talking about a “future method” (it’s planned, but it does not exist).

---

<div class="post-metadata">

**Author:** ![OjunbamO](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@OjunbamO](https://discourse.gohugo.io/u/OjunbamO)\
**Post date:** [March 13, 2020, 7:08am UTC](https://discourse.gohugo.io/t/hugo-paginator-range-for-subdirectories/23957/7 "2020-03-13T07:08:29Z")

</div>

Yea I think that would fix my problem.

I just build a little workaround:

```auto
{{ if in .Permalink "/posts/" }}
	{{ range (where .Site.RegularPages "Section" "posts") }}
		<a href="{{.Permalink}}">{{- .Title -}}</a>
	{{ end }}			
{{ else }}
	{{ range .Paginator.Pages }}
		<a href="{{.Permalink}}">{{- .Title -}}</a>
	{{ end }}
{{ end }}

```

The only problem with this now, is that it’ll show all entries of /posts on all list series: /posts/_whateverseries_ + the pagination won’t work (but I think thats tolerable)

Does anyone know how to build a little workaround for that? With an extended if statement or something?

Regards
