Count the pages in a Hugo section
If you need to show how many pages belong to a Hugo section, filter .Site.RegularPages by its Section value and pass the result to len:
<p>Total number of pages in the /articles/ section:
{{ len (where .Site.RegularPages "Section" "==" "articles") }}.
</p>
Using .Site.RegularPages keeps section pages and other list pages out of the count. Replace articles with the name of the section you want to measure.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- How I Organize My Hugo Site
A predictable Hugo structure for content, page resources, layouts, assets, static files, and configuration.
- When to Use Hugo Shortcodes or Render Hooks
Use render hooks to change normal Markdown output and shortcodes for custom content with meaning Markdown cannot express.
- Customizing Hugo’s RSS Feed
Adjust Hugo RSS titles, descriptions, content, and section filtering while keeping the generated feed valid and easy to discover.