Risan Bagja

List Pages with Specific Tag on Hugo

We can combine the range and the where functions on Hugo to get a list of pages with some specific tag. Let say we want to get the first 5 recent pages that contain the logbook tag, we can achieve it like this:

    {{- range first 5 (where .Site.RegularPages "Params.tags" "intersect" (slice "logbook")) -}}
        <a href="{{ .RelPermalink }}">{{ .Title }}</a>
    {{- end -}}

The intersect operator accepts an array, that’s why we need to turn the logbook into an array first.