How to list posts from a designated contents sub-folder

With Hugo 0.34, ghostwriter theme now displays all my posts, including my about and contact pages, which is concerning because I just want my blog posts to be listed.

In my content folder, like the base ghostwriter example site, there are the page, post, and project folders. Before version 0.34, all my listed posts were my blog posts from the /post folder.

I figured there has to be some way to work around this, and so I went to the layouts and I found the template for my blog list.

<ol class="post-list">
    {{ $pag := .Paginate .Data.Pages }}
    {{ range $pag.Pages }}
        {{ partial "post-stub.html" . }}
    {{ end }}

I think it has to do with the $pag.Pages and Data.Pages, but I dont know how I can alter this to call from a specific subfolder, namely post. Any tips?

1 Like

Check out the Introduction to templates… look for range where examples, there and in this forum too. There are many!

I just ran into this as well. Did you ever figure out what it was?

Might be a bit late, but hey…

If you only want to display pages which are in a defined section (e.g. posts), you can use range where:

{{ range where .Pages "Section" "posts" }}
{{ .Title }}
{{ end }}
1 Like