First post on the list of posts (and single post)

Apologies for 2-in-1, but trying to figure out something that relates to each others.

  1. On the Blog page (list of posts) I would like to catch 1st posts and apply for it different formula than for others.

The first post is always above fold hence would like to apply if else for it.
Mostly for featured image that load lazy above the fold.

Rough idea:

{if 1stPost_on_List} loading="eager" {else} loading="lazy"
  1. When visiting a single post the featured image is loaded again and would like to apply ‘if’ single page for the featured image to remove lazy loading.

I got one featuredImage.html formula that I don’t really want to split for one (without lazy loading) for single and one for list of posts. I would prefer to use ‘if’ approach.

Rough idea:

{if is_single_post} loading="eager" {else} loading="lazy"

Appreciate for advise.

Hugo will generate the lists static! All is in ONE page. Forget about eager or lazy.

{{ range $k, $v := .Site.RegularPages }}
  {{ if not $k }}
    I am the first item.
  {{ end }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}

Use .IsPage. See


maybe this can help

1 Like