Listing blog posts on homepage not working

I have a site structure that looks like this:

_index.md
  -/blog
    -_index.md
    -post1.md
    -post2.md
  -/another-section
    -subpage1.md
    -subpage2.md

I’d like to list out only the posts under /blog on my site homepage, ignoring subpages under “another-section”. On my index.html template, I have a range that looks like this:

{{ range where .Pages "Section" "blog" }}
    <article>
        <h3><a href="{{ .RelPermalink }}">{{ .Title }}</a></h3>
    </article>
{{ end }}

However, on the homepage of my site, the only thing that gets listed is “Blog,” linking to /blog. This seems like a fairly straightforward range that I saw other people use for this specific purpose, so I’m having trouble understanding where I’ve gone wrong!

If you’d like to see what’s happening live, my site is https://samlinville.com and the repo is at https://github.com/samlinville/hugo-sammy

{{ range where site.RegularPages "Section" "blog" }}

Docs: Site variables | Hugo

1 Like

Also possible with .GetPage

{{ range (.GetPage "/blog").Pages }}
<article>
  <h3><a href="{{ .RelPermalink }}">{{ .Title }}</a></h3>
</article>
{{ end }}
1 Like

Thanks both! One difference I noted between your suggestions (for posterity, if someone else stumbles across this)

If my site structure included subposts under some of the blog posts, like this:

_index.md
  -/blog
    -_index.md
    -post1.md
    -/post2
      -_index.md
      -subpost1.md
      -subpost2.md
    -post3.md
  -/another-section
    -subpage1.md
    -subpage2.md

And I only want to list out Post 1, Post 2, and Post 3 (without listing Subpost1 and Subpost2)
Then @acanalis solution works, as the other solution will ignore the list page of Post 2, and display all of the subpages under post 2 instead.

Again, thanks both for your help!

1 Like

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