shou2017.com
JP

Hugo: How to Exclude Fixed Pages from List Pages

Tue Sep 24, 2019
Sat Aug 10, 2024

When creating a blog with Hugo, you’ll likely create not only blog posts but also fixed pages like an about page. In my case, I have a post folder and an about.md file, so I want to exclude this about page from the blog list.

Hugo: How to Exclude Fixed Pages from List Pages

Simply using the range FUNCTION will display all articles under the content directory in the list.

<ul>
     {{ range .Pages }}
     <div class="article-box">
          <div class="article-list-img">
               <img src="/images/ubuntu-logo.jpg">
          </div>
          <div class="article-list-title">
               <a href="{{ .RelPermalink}}">{{.Title}}</a>
          </div>
     </div>
     {{ end }}
</ul>

So, we use the where FUNCTION. Here, I simply want to display only articles from the post folder in the list, so I’ll do the following:

<ul>
     {{ range (where .Pages "Type" "post")}}
     <div class="article-box">
          <div class="article-list-img">
               <img src="/images/ubuntu-logo.jpg">
          </div>
          <div class="article-list-title">
               <a href="{{ .RelPermalink}}">{{.Title}}</a>
          </div>
     </div>
     {{ end }}
</ul>

With just this, you can display the list without including fixed pages.

See Also