List page for all content of all sections

Hey there,

first off: I am still very new to Hugo, so excuse my newbieness.

I am using the grid side theme right now, but I don’t think that my question is related to a specific theme.

What I am trying to achieve:
Create several sections which are all handled as blog sections (with the same layout/template), but differ content-wise.
For example: &
With that structure built, I would like a third page, let’s say where you find both the articles of sectionA and sectionB listed, ordered by date.

Is something like this possible? If so, how would I have to approach that?

Thanks in advance!

Yup. You can access all pages via .Site.Pages. Check the docs for how to display content. Sounds like you may want to looking into the where function specifically.


Amazing! Thank you, rdwatters.

I didn’t expect it as easy as:
{{ range where .Site.Pages "Section" "sectionA" }}

How can I use that command for several sections, though? Tried things like
{{ range where .Site.Pages "Section" "sectionA" "sectionB" }}
{{ range where .Site.Pages "Section" "sectionA","sectionB" }}
{{ range where .Site.Pages "Section" "sectionA"||"sectionB" }}
…none of those work. Couldn’t find any answer in the docs…

This user is starting to realize how amazing Hugo is. :monkey:

1 Like

This should work

{{ range where .Site.Pages "Section" (or "sectionA" "sectionB") }}

Doesn’t work either unfortunately. Only lists content for sectionA for some reason… =/

@inspiritana Can you point me to a repo for this (if public)?
@parsiya I see where you were going, but I don’t think where works with the logical or operator in this use case.

There is more than one way to do this, depending on the number of sections. For example, if you have three sections (One, Two, Three) and only want to disinclude one in the list page, you could do something like this (assuming you want the most recent first, otherwise you can omit .ByPublishDate.Reverse):

<ul class="section-one-and-two-pages">
{{ range .Site.Pages.ByPublishDate.Reverse }}
    {{ if or (eq .Section "One") (eq .Section "Two")}}
{{ end }}

Or if you just want to omit section Three and want to show sections One and Two, it could be DRYer with the following. This will also be easier if your plan is to, say, create 10 sections and only leave one out since you won’t have to modify your code at all on the “overview” page:

<ul class="section-one-and-two-pages-by-just-omitting-three">
{{ range where .Site.Pages.ByPublishDate.Reverse "Section" "!=" "Three" }}
{{ end }}

Thank you so much, rdwatters! This is exactly what I needed. Both versions work like a charm. I’ll stick to the latter, as there is indeed just one section to be excluded (atm).

I haven’t created a repo yet. I’m not confident with using git yet, so I need to figure out how exactly I do that stuff.

@inspiritana Glad it worked.

Word to the wise: learn git sooner rather than later. It will save you a lifetime of frustration :smile: