List is displaying content from the wrong section

For this Hugo site, I have two sections in my “content” folder, “posts” and “projects”, each with their own pages. The site.com/projects/ and site.com/posts/ pages display their relevant content correctly. On my home page, I’d like to display some entries from both sections. Here is layouts/index.html:

{{ define "main" }}
    <div class="homepage-content">
        {{ .Content }}
    </div>
    <h1>Blog Posts:</h1>
    <div class="articles">
        {{ $post_pages := where (where site.Pages "Type" "in" "posts") "Params.hidden" "!=" true }}
        {{ range (.Paginate $post_pages).Pages }}
            {{ partial "post-summary.html" . }}
        {{ end }}
    </div>
    <h1>Projects:</h1>
    <div class="articles">
        {{ $project_pages := where (where site.Pages "Type" "in" "projects") "Params.hidden" "!=" true }}
        {{ range (.Paginate $project_pages).Pages }}
            {{ partial "post-summary.html" . }}
        {{ end }}
    </div>
    {{ partial "pagination.html" . }}
{{ end }}

What happens is, that both code blocks end up rendering a list of the pages from the “posts” section, and if I reverse the order (placing the code block for the “projects” section first) they both display pages from the “projects” section. What seems to be happening is that there’s some kind of hidden variable that isn’t being reset between the code blocks. After going through the Hugo docs for about an hour, I couldn’t for the life of me find the reason. I’ve already specified both sections under “mainSections” in the params file if that makes any difference (although I don’t imagine it does)

For reference, I’m using the anubis theme as a base (although it’s been somewhat heavily modified) but again, I don’t think it’s related.

Thanks in advance for any answers!

Issues:

  1. You are trying to paginate twice in the same template—you can’t do that.
    See https://gohugo.io/templates/pagination/
  2. When building your page collection, use .RegularPages instead of .Pages.
    See https://gohugo.io/variables/page/#pages

Options:

  1. If you want to paginate, build a sorted collection of both posts and projects, then paginate the collection.
    See https://gohugo.io/functions/union/
  2. Display the first N posts under the Posts heading (with a link to more), and display the first N projects under the Projects heading (with a link to more).
    See https://gohugo.io/functions/first/
1 Like

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