List blog posts with limit and offset combined

Hi All,

I have a page where the blog landing showcases the latest three posts with the latest one being on the top in one column and the other two below it in a split of two columns, a crude example of what I mean is below.



I am using the range tag as follows

{{ range first 1 .Site.Pages }}{{ if eq .Type “blog” }} {{ .Title }} {{ end }}{{ end }}

And the above fetches the latest blog post title perfectly.

The second call is as follows

{{ range after 1 .Site.Pages }}{{ if eq .Type “blog” }} {{ .Title }} {{ end }}{{ end }}

This returns the other articles with the offset of 1, it works fine however I would like to limit to just show 2 articles. In which case the code would be the below, however with it I lose the offset.

{{ range first 2 .Site.Pages }}{{ if eq .Type “blog” }} {{ .Title }} {{ end }}{{ end }}

Is there a way to include both the offset ability and a limit in the same call?


{{ range  first 2 (after 1 .Site.Pages) }}{{ if eq .Type "blog" }}  {{ .Title }}  {{ end }}{{ end }}

The above would be even better if you combine it with where to get rid of the if eq type blog construct.

1 Like

Thanks bep, that worked a treat.

I attempted to clean it up with how you suggested but couldn’t chain correctly.
{{ range first 2 ( where .Site.Pages “Section” “blog” ) }} {{ end }}
This worked fine to output the latest two posts but I couldn’t place (after 1 .Site.Pages) or after 1 anywhere without it breaking. To stack a third arguement do you need to prefix it differently?


Thank you for the help for my problem, mine was very similar. I fixed the stacking with this line:

{{ range first 4 (after 1 (where .Site.Pages "Type" "post")) }}

Worked brilliantly for what I’m working on — thanks!