Get the second post in a list

While I am aware of first and after, is it possible to get the second post in a list separately? I want the first and second posts to share a featured class, but only the first to have a span with ‘new’ HTML tag.

You can use the index function. It’s zero based, so index 1 is page 2.


{{ $page := index site.RegularPages 1 }}
{{ $page }}


I should have mentioned I am using this with $paginator. And only on page 1.

In that case, am not sure.

{{ range $k, $_ := (.Paginate (where site.RegularPages "Type" "post")).Pages }}
  {{ if and (eq $.Paginator.PageNumber 1) (eq $k 0) }}
    {{/* First pager, first post */}}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  {{ else if and (eq $.Paginator.PageNumber 1) (eq $k 1) }}
    {{/* First pager, second post */}}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  {{ else }}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  {{ end }}
{{ end }}
{{ template "_internal/pagination.html" . }}

Thanks! This helped a lot.

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