Omitting content

I have the current as the index.html of my site:

<!doctype html>
<html>
  <head>
    {{ partial "head.html" . }}
    <link rel='stylesheet' href='/index.css'>
  </head>
  <body>
    {{ partial "header.html" . }}
    {{ .Content }}
    <!-- Group by year. -->
    {{ range .Site.RegularPages.GroupByDate "2006" }}
    <h2>{{ .Key }}</h2>
      <!-- Group by month. -->
      {{ range .Pages.GroupByDate "January" }}
      <h3>{{ .Key }}</h3>
        <!-- Orders content according to the "date" field in front matter. -->
        {{ range .Pages.GroupByDate "02" }}
        <h4 class='postdate date'>{{ .Key }}</h4>
        <ul> 
          {{ range $index, $post := .Pages }}
            <li>
              <time datetime="{{ $post.Date.Format "2006-01-02T15:04:05Z0700" }}">
                <span class='postdate day item-{{ $index }}'>{{ $post.Date.Format "Mon" }}</span>
              </time>
                <span class='postdate'>{{ $post.Date.Format "15:04" }}</span>
              <a id='{{ $post.Date.Format "20060102T150405Z0700" }}' class='posttitle' href="{{ .RelPermalink }}">{{ $post.Title }}</a>
            </li>
          {{ end }}
        </ul>
      {{ end }}
    {{ end }}
  {{ end }}
  {{ partial "footer.html" . }}
  </body>
</html>

The issue with it is that an “About” page, or anything else will show as part of the list. How could I modify this, so that only /content/posts, for example, show on this list?

The traditional way of doing this would be to create “where filters” (see docs).

However, for your use case I would look at

Also note the cascade keyword.

With that you can tell Hugo “not to list” certain pages. This way of doing it will be more portable vs. themes etc.

1 Like

Wow! That Build Options is so powerful, and does exactly what I needed! Thank you very much for the fast reply, and on-point solution.

For others like me—that is, with similar setup—looking to, say, “unlist” an about page, simply add:

_build:
   list: false

to the page Front Matter. That works for everything, like custom error pages, etc.

1 Like

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