Pagination Sort By File Path

IMG_20240220_155404

I have this code on my layouts/_defaults/list.html and it works good with pagination.

{{ range (.Paginate (.Pages).Reverse).Pages }}
<article class="box">
<a href="{{ .Permalink }}">
<div class="title">
<h2>{{ .Title }}</h2>
</div>
<div class="content">
<p>
{{ .Summary }}
</p>
</div>
</a>
</article>
{{ end }}

I only need one last step.

How to make it sorted and paginated by file path, not by weight or alphabetical title?

{{ $p := sort (where site.RegularPages "Section" "posts") "Path" "asc" }}
{{ range (.Paginate $p).Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}

Requires Hugo v0.123.0 or later.

1 Like

It doesn’t works. List doesn’t appear.

Yes, it does. Try it.

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