How to list all pages in a section but not the index page

I am trying to create a list of all the pages in a section from within a single.html template. If I use the code:

{{ $section := where $.Site.Pages "Section" "blog-archive"}}

And range through it, I get a list of all the blog-archive pages, but also the index page. Is there a way to exclude the index page in the where?

Thank you!

1 Like

It looks like I can do an if statement and filter by .Kind inside of the range to accomplish this, as in:

{{ if ne .Kind "section" }}

But, is there a way to add this filter directly in the where statement?

Try changing $.Site.Pages to $.Site.RegularPages


That was it, thank you! Here’s the relevant section of the docs that talk about $.Site.RegularPages

1 Like

Here’s a simple way to create Section Menus. The following code can be copied into a partial template, which can then be included within a section template. Setting the variables at the top is not the most “magical” way to do this, but it does make it trivial to duplicate and modify new templates for other sections.

{{ $title := “Your Section Title” }}
{{ $section := “your_section” }}

<div class="panel-heading">
  <h3 class="panel-title">{{ $title }}</h3>

<div class="panel-body">
    <ul class="nav nav-pills nav-stacked">
      {{ range (where .Site.RegularPages.ByTitle "Section" $section ) }}
        <li><a href="{{ .Permalink }}">{{ .Params.title | humanize | title }}</a></li>
      {{ end }}

This example was really useful, thanks.