I want a list of posts from my blog to show on the home page. My issue is that this code block…
<ol class="post-list">
{{ $pag := .Paginate (where .Data.Pages "Type" "post") }}
{{ range $pag.Pages }}
{{ partial "post-stub.html" . }}
{{ end }}
</ol>
renders all of the items in post
and page
when I want it to leave the pages like about.md
and contact.md
out of the list. What is wrong with the way the range is defined here?
The syntax seems correct.
You need to share a link to your repo for others to see what’s wrong.
Something strange is going on here and I cannot figure out what’s going on.
I also noticed that on the demo page of the Ghost Writer theme all pages are shown on the homepage even though the template has {{ $pag := .Paginate (where .Data.Pages "Type" "post") }}
.
Maybe you should open a Github issue with the theme’s author. Or maybe someone else can look into this.
Took me a while but I finally figured out what’s wrong.
Since Hugo 0.18 everything in Hugo is a page internally.
The author of the Ghost Writer theme has defined layouts for a Page
section.
And that messes up with Hugo’s default template look-up order. So that your homepage layout is not controlled by /layouts/index.html
as it should but by /themes/ghostwriter/layouts/page/list.html
Simply changing the line {{ $pag := .Paginate .Data.Pages }}
to {{ $pag := .Paginate (where .Data.Pages "Type" "post") }}
in the above template will solve your problem.
May I suggest you open a Github issue in the theme’s repo about this. The author of the Ghost Writer theme needs to restructure it.
Also since this is one of the weirdest theme bugs I’ve come across I think that @bep and @digitalcraftsman need to know about it.
Thanks so much @alexandros. I’ll open up that issue.
Just a minor unrelated note; you do not need to use .Data.Pages
… just .Pages
works – ref.
1 Like