[Hugo] Hiding pages from pagination

It seems like for some reason all of the ‘pages’ in this blog were appearing in the pagination - I just never noticed because they were at the end (undated) and untagged so they never appeared in any of the archives. Who even spends their time navigating to the very first post on this blog? I only noticed because I used the same code to generate a site containing 1 post(s) and all the pages popped up at the top.

Nonetheless there’s a fix, it seems. I always have trouble finding information to help me on Hugo things, unlike Jekyll which seems to have a wider following. Eventually I stumbled on this post on the Hugo discussion boards which gave me what I needed.

This is the original line at the top (with an {{ end }} tag at the end):

{{ range .Paginator.Pages }}

I tried first to show only ‘post’s in the pagination (extra {{ end }} required at the bottom):

{{ range .Paginator.Pages }}
{{ if eq .Type "post"}}

This hid the pages, but for some reason the same ‘next’ and ‘back’ buttons still appeared even though there were no posts or any content at all displayed.

This did the trick:

{{ range (.Paginate (where .Data.Pages "Section" "==" "post")).Pages }}

Creating success from other’s problems, boo-yeah.