Hello.
I want to add a id
selector to the first post on each page generated by Hugo Pagination. Is this possible?
In my index.html
, I use pagination as follows:
{{ $paginator := .Paginate (where .Site.RegularPages "Type" "in" .Site.Params.mainSections) }}
{{ range $paginator.Pages }}
{{ range first 1 $paginator.Pages }}
{{ .Scratch.Set "firstID" "customID" }}
{{ end }}
<!-- post display -->
{{ end }}
This is another way I tried (in my list.html
):
{{ range .Paginator.Pages }}
{{ $firstPost := index $.Paginator.Pages 0 }}
{{ if eq $firstPost.Permalink .Permalink }}
{{ .Scratch.Set "firstID" "customID" }}
{{ end }}
<!-- post display -->
{{ end }}
In both the ways, I set the id
using:
<div id = "{{ .Scratch.Get `firstID` }}">
<!-- post content -->
</div>
Both ways aren’t giving the correct results. The first one seems fine, but, only on the first page, on second and other pages, it adds the ID to all the posts.