Limit taxonomy type

Hi all,
I’m not sure how to do this so wanted to ask here. How can I limit the number of posts for a taxonomy term?
I am using the latest version of HUGO.

My code snippet:

{{ range .Site.Taxonomies.foo.bar }}
  {{ partial "baz" . }}
{{ end }}

I tried {{ range first 5 (where .Site.Taxonomies.foo.bar) }} but then gave me an error saying it expected two but only got one.

Thanks in advance.
Emma

I haven’t verified but try using parentheses to make it clear as to which arguments go to range and which go to first: {{ range (first 5 (where site.Taxonomies.foo.bar)) }}

Update Sorry for the bad advice above; @jmooring has fixed that.


Also, it’s more canonical to use site. instead of .Site.. That way you never end with with an issue of attempting to get the Site object from a wrong scope.

1 Like

There’s no need to use a where clause here.

{{ range first 5 .Site.Taxonomies.foo.bar }}
2 Likes

Thank you so much! This worked for me. If I replace first with shuffle it doesn’t work, how could I shuffle 5 posts from the .foo.bar taxonomy.

{{ range shuffle 5 .Site.Taxonomies.foo.bar }}

This did not work (

{{ range (first 5 .Site.Taxonomies.foo.bar | shuffle) }}
1 Like

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