Get a list page in a nested section, consisting of tags from the blog section

I don’t quite have the programming chops, but I have been using Hugo quite a while now.

This is the structure of my contents folder

.
├── about.md
├── archive.md
├── blog (lots and lots and lots of posts)
├── more
│   ├── fitness.md
│   └── _index.md
├── projects
│   ├── _index.md
│   └── other-projects
│       └── _index.md
├── reading
└── subscribe.md

What I am struggling to do, is create a list in the other-projects folder, of posts tagged other-projects in my blog folder.

Been looking all day, and am thoroughly confused.

If any one could help, or point me somewhere, I’d be really grateful

content/projects/other-projects/_index.md

+++
title = 'Other projects'
date = 2024-01-08T10:51:03-08:00
draft = false
layout = 'blogs-tagged-other-projects'
+++

layouts/_default/blogs-tagged-other-projects.html

{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Content }}
  {{ $p := where site.RegularPages "Section" "blog" }}
  {{ $p = where $p "Params.tags" "intersect" (slice "other-projects") }}
  {{ range $p }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ end }}
{{ end }}

https://gohugo.io/templates/lookup-order/#target-a-template
https://gohugo.io/functions/collections/where/

1 Like

You’re godsent @jmooring!

It worked!

The missing piece for me was understanding a layout was needed and where to put it.
(I found various examples of ranging and I was somehow trying to get it to work by making a shortcode that would put in html into my _index.md)

The way you showed it, makes so much more sense.

Thank you so much, once again :slight_smile:

1 Like

Update: I got it to look just the way I wanted.
From what you taught me, and the links you pointed me to, I figured I could reuse my theme’s list layout for my custom list too.

So I used that as my layouts/_default/blogs-tagged-other-projects.html and dropped your range code, in there.

Thank you so much once again, @jmooring!

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