Paginator range limiting

Hello, me again.

I’m working on this site, the issue I’m having is that every file in the content directory is added to the main page list list.html and it’s associated pagination.

I’ve come across two potential fixes, but both are giving me issues.

  1. Insert {{ if .PublishDate }} after {{ range which works, but the paginator is still listing as if it’s not looking at the if statement (which makes sense as it comes after). I’ve tried messing around with $index and $element, and throwing if and where statements around but can’t seem to get anything working. The ‘post break’ here is on page 8.

  2. Insert a where .Data.Pages "Type" "posts" (found on this site) which filters EXACTLY how I want it, but gives me a weird posts submenu that I need to click into to see my post list. In this example, the ‘post break’ is on page 5.

Any help would be much appreciated.

Try
Portable where filters – site.Params.mainSections

I’ve added mainSections = ["posts"] and tried content\posts too, however this doesn’t seem to have made any difference to the items displayed.

Do I need to alter my config file any more, or is my range still incorrect?

You don’t need mainSections = ["posts"]. Your range should look something like:

    {{ $paginator := .Paginate (where .Site.RegularPages.ByDate.Reverse "Section" "posts") -}}
    {{ range $paginator.Pages -}}
		<li><h3><a href="{{ .Permalink }}">{{ .Title }}</a></h3><span>{{ .PublishDate.Format "Jan 2, 2006" }}{{ if ne .Lastmod .PublishDate }} updated{{ end }}, {{ .ReadingTime }} min read</span></li>
		{{ end }}

Thanks, your code worked absolutely flawlessly and did exactly what I wanted it to. I thought the example was leaning more towards config edits vs hard coding options in a theme, my mistake.

Thanks for your help.

Your welcome!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.