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.
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.