Custom first element in range on (each) pagination page

I saw some posts on the forum related to this, however, none of them solves this aspect.

I got the below code that lists all pages Titles and paginates is if more than 10.

{{ $p := where site.RegularPages "Params.hidden" "ne" true }}
{{ range (.Paginate $p).Pages }}
<li>{{ .Title }}
{{ end }}

What I am looking for is how to make always the 1st result on the paginated page (first Title in that instance) appear in a different format. Lets say

<li><strong>{{ .Title }}</strong>

Ignore use of

  • as can select 1st LI from CSS and apply custom style. My example is purely theoretical and on the end, I would like to apply this to different properties like Featured Image (where on first tesult on the page, the image will not be lazy loaded, but other will be).

    To be task-specific,
    I want to 1 (first) element to add fetchpriority=high where to all else fetchpriority=low on 1st page, and same approach on other pages in pagination.

On my blogs front page I render the first three posts as “summary” and the rest as “li”.

{{ range first 3 (where .Site.RegularPages "Type" "post") -}}
{{ .Render "summary" }}
{{ end -}}
{{ range after 3 (where .Site.RegularPages "Type" "post") -}}
{{ .Render "li" }}
{{ end -}}

Nice idea, but is it working with pagination?

What I managed soo far

{{ if eq (index $p 0).Permalink .Permalink }}first post{{ else }}next{{ end }}

This will say FIRST POST to the first in the range, and NEXT for the rest.
However this will not see, that on /page/2/ the 1st result is the first on the index, as its not.

Ok, I made it…

      {{ $p := where site.RegularPages "Params.hidden" "ne" true }}
      {{ $pp := (.Paginate $p).Pages }}
      {{ range $pp }}


{{ if eq (index $pp 0).Permalink .Permalink }}first post{{ else }}next{{ end }}

will return FIRST POST on the post in pagination.

And this is what I think been looking for :slight_smile:

Maybe it can be simplified in some way, but at least its working.

This didn’t work?

Struggle with pagination on that solution, and decided to start fresh. Probably right now will work on both when paginating before range.

You are right. I found this which might work for you.

This works as expected, displaying the first item on each pager in bold.

  {{ range $k, $v := (.Paginate .Pages).Pages }}
    {{ if not $k }}
      <li><strong>{{ .Title }}</strong></li>
    {{ else }}
      <li>{{ .Title }}</li>
    {{ end }}
  {{ end }}
{{ template "_internal/pagination.html" . }}

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