- Hugo has pages assigned to different categories.
- All these categories appear on the list page for categories.
- I would like to add a featured image to the categories in the category list page.
- However, these images should come from the images named
featured.**
for each page from the assets folder (see point 5 for test site) - Here is my content structure Use Content Adapters to get several images - #4 by jmooring
- Anyone with the knowledge to assist please?
ChatGPT came up with this. If anyone has an alterative method, I am all ears
{{- if eq .Type "categories" }}
{{- $categories := .Site.Taxonomies.categories }}
{{- range $category, $pages := $categories }}
{{- $featuredImage := "" }}
{{- range $pages }}
{{- with resources.GetMatch (printf "images/%s/%s/featured.*" .Section .Params.sku) }}
{{- if not $featuredImage }} {{- $featuredImage = .Process "resize 300x300" }} {{- end }}
{{- end }}
{{- end }}
{{- if $featuredImage }}
<div class="category-featured-image">
<img src="{{ $featuredImage.RelPermalink }}" class="transition" width="{{ $featuredImage.Width }}" height="{{ $featuredImage.Height }}" alt="Featured image for {{ $category }}">
</div>
{{- end }}
{{- end }}
{{- end }}
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.