Hey everyone, sorry if this was asked before. I’m trying to loop through only the pages in the projects section on my home page. Instead, I’m getting all of the pages including about.html and contact.html.
I’m trying to exclude the last two. Any input would be appreciated.
content
├── projects
│ ├── first.md
│ ├── second.md
│ ├── third.md
├── contact.html
├── about.html
<ul>
{{ range .Paginator.Pages.ByPublishDate.Reverse }}
<li style="padding: 10px;">
<a href="{{ .RelPermalink }}">
<div>
{{ .Date.Format "2006-01-02" }}
</div>
<div>
{{ .Title }}
</div>
</a>
</li>
{{ end }}
{{ template "_internal/pagination.html" . }}
tut
October 28, 2022, 6:25am
2
Try this (haven’t tested yet since I’m on mobile )
<ul>
{{ $p := where site.RegularPages "Section" "projects" }}
{{ range (.Paginate $p).Pages.ByPublishDate.Reverse }}
<li style="padding: 10px;">
<a href="{{ .RelPermalink }}">
<div>
{{ .Date.Format "2006-01-02" }}
</div>
<div>
{{ .Title }}
</div>
</a>
</li>
{{ end }}
{{ template "_internal/pagination.html" . }}
Hey thanks for the quick response.
That method didn’t resolve the issue
Getting the same result.
It works properly when I’m on the projects page, but from my understand it’s because range.Pages loops over the current directory / section. I’m just trying to reproduce that same effect on the home page
tut
October 28, 2022, 6:42am
4
include a link to the source code repository of your project
Please read and follow the below guidelines before asking for help in the forum.
DOCS | THEMES | NEWS | GITHUB | FAQ | RELEASE NOTES
How to Request Help
Welcome to the Hugo forums and thanks for using Hugo! The below are a few friendly tips on getting help from the other Hugo volunteers in this forum.
Some Knowledge Required
Dare we say that while Hugo is indeed pretty magical, it is not meant to be a “magic wand” to suddenly give you a published website a la Square Space or Wordpress. You …
Sorry, relatively new to this.
Link
yes! that was the case. thanks for pointing that out
tut
October 28, 2022, 9:38pm
10
Add this code to the front matter of both pages
_build:
list: never
That solved the issue!
Would you point me out to the docs or expand on how you came to that solution ?
Thanks again!
There’s a simpler way to handle this. Build and sort the page collection before you paginate.
{{ $p := (where site.RegularPages "Type" "projects").ByPublishDate.Reverse }}
{{ range (.Paginate $p).Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}
4 Likes
tut
October 29, 2022, 5:47am
14
@luckyduckyquackquack use this instead. But take note of the link I shared in case you want to use it in future.
thanks for this solution!
system
Closed
November 1, 2022, 8:28am
17
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.