HUGO

Show different related posts in one section only

I am using the code below to show related posts. How can I wrap it in an if else statement so I show different related posts for one section called views?

  {{ $filteredPosts := ( where (site.RegularPages.Related .) "Type" "post") }}  
    {{ $relatedPosts := shuffle $filteredPosts | first 6 }}  
    {{ range $relatedPosts }}  
      <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
      {{ end }}
{{ if eq .Section "views" }}

I’m not sure I understand correctly but the condition you’re looking for is a test on .Section ( a string)

1 Like

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