Exclude posts from a list containing a specific tag

Hello Hugo users,

I use the following code as a Shortcode template to list the first 10 posts tagged with “show”:

{{ if .Site.Taxonomies.tags.show }}
<h2>Show in list</h2>

<ul>
    {{ range first 10 .Site.Taxonomies.tags.show }}
    <li>
        <a href="{{ .RelPermalink }}">{{- .Title | markdownify }}</a>
    </li>
    {{ end }}
</ul>

{{ end }}

Now I wonder if it is possible to exclude posts containing a specific keyword (e.g. “exclude”)?

I have already looked around here in the forum, but found no suitable example. I would be very happy about suggestions and examples.

Many thanks in advance
somnium

Untested, but see if this works

{{ if not .Site.Taxonomies.tags.show }}

Thanks for your reply, Zachary. The following code does not work:

{{ if not .Site.Taxonomies.tags.exclude }}
<h2>No "exclude" in this list</h2>

<ul>
    {{ range first 10 site.RegularPages }}
    <li>
        <a href="{{ .RelPermalink }}">{{- .Title | markdownify }}</a>
    </li>
    {{ end }}
</ul>

{{ end }}

Try it this way instead:

<h2>Posts without "show"</h2>

<ul>
{{ range first 10 site.RegularPages }}
  {{ if not (in .Params.tags "show") }}
  <li>
    <a href="{{ .RelPermalink }}">{{- .Title | markdownify }}</a>
  </li>
  {{ end }}
{{ end }}
</ul>
1 Like