Is it possible to have a custom URL for a category list page?

I have /content/tool/

And then /content/tool/toolone.md

categories: [ “Best”, “Web” ]

/content/tool/tooltwo.md

categories: [ “Best”, “App” ]

etc

I’d like to have a URL “root.com/best-tools/” (and not root.com/tools/best/, which is what it would be by default)

and I’d like root.com/best-tools/ to list all of the tools with the category “Best”

Is that possible, without resorting to a very hacky solution?

I would just create the best-tools page and list out what you want there. Don’t know if that’s what you’d consider hacky, but I think it’s the simplest solution.

1 Like

Or you can set the /best-tools page to redirect to /tools/best by having it contain something like:

<!doctype html>
<html lang="en">
    <head>
        <title>Best Tools</title>
        <meta http-equiv="refresh" content="0; URL='https://root.com/tools/best'" />
    </head>
</html>

You would need to save that as layouts/section/best-tools.html in your site repo.

1 Like

I’d set an alias for the term first.

1 Like

Thank you all. I’m going to create the best-tools page and list out what I want there.

Bud, I apologize in advance for the incoming “noob question.”

Is the right way to do that the following?

  • Create /content/tool/best-tools.md

  • Create /layouts/tool/list.html that ranges through all of the tools where their category contains ‘best’. However when I do this, I’d need to make it /single.html to display for that page, because best-tools.md isn’t a “list”.

I’m a little confused and wondering if there’s any way you could point me in the right direction on a) where the right place would be to create the markdown file for this, and b) which layout template would be the right place to do that?

What you can do is to create tools/best/_index.md with something like this in front matter:

---
title: "The Best Tools!"
url: "/best-tools/"
---

@bep I tried what you wrote and it didn’t seem to work, so I wonder if there may be a bug?

Here’s how to reproduce:

hugo version Hugo Static Site Generator v0.30.2

hugo new site bug-repro-site

cd bug-repro-site

cd themes

git clone GitHub - spf13/hyde: Port of Mdo's excellent theme to Hugo

cd …/

hugo new tool/toolone.md

---
title: "Toolone"
date: 2017-11-03T13:20:44-07:00
---

Tool one

hugo new tool/tooltwo.md

---
title: "Tooltwo"
date: 2017-11-03T13:20:47-07:00
---

Tool two

hugo new tool/best/_index.md

---
title: "Best tools page"
url: "/best-tools/"
---

config.toml

baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "hyde"

Expected result in sitemap

<url>
<loc>http://localhost:1313/best-tools/</loc>
<lastmod>2017-11-03T13:23:56-07:00</lastmod>
</url>

Actual result

<url>
<loc>http://localhost:1313/tool/best/</loc>
<lastmod>2017-11-03T13:23:56-07:00</lastmod>
</url>

http://localhost:1313/best-tools/

404 page not found

Am I missing something or doing something wrong, or is this a bug and you’re able to reproduce? I may well be doing something wrong, so I included all of my steps to help diagnose.

I tried again following it to the letter (i.e. including the (s)), with the same result. I’ll update my previous “reproducing” post and run it all again, just to make sure though.

OK I read your post wrong. Put this in categories/best/_index.md.

Note that there are open issue(s) to improve the above.

Ok thanks @bep I’ve tried again, but still seems to not be working for me. Am I doing something incorrectly or is there possibly something wrong with my hugo installation?

Repro steps

hugo new site repro-site

cd repro-site

cd themes

git clone https://github.com/spf13/hyde

cd …/

hugo new tools/toolone.md

---
title: "Toolone"
date: 2017-11-03T13:20:44-07:00
categories: [ "Best" ]
---

Tool one

hugo new tools/tooltwo.md

---
title: "Tooltwo"
date: 2017-11-03T13:39:58-07:00
categories: [ "Best" ]
---

Tool two

hugo new categories/best/_index.md [Did I put that in the right place? It’s in /content/categories/best/_index.md Seems to be same result in /categories/best/_index.md]

---
title: "The Best Tools!"
url: "/best-tools/"
---

config.toml

baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "hyde"

Result:

<url>
<loc>http://localhost:1313/categories/best/</loc>
<lastmod>2017-11-03T13:39:58-07:00</lastmod>
</url>

I might remember wrong. Forget my suggestion.

@bep Okay :slight_smile: Thanks for the help. Do you have any other suggestions of how I might achieve this? Or tips on @budparr 's suggestion in terms of a) where the right place would be to create the markdown file for this, and b) which layout template would be the right place to do that?

I’ve been out and have some family in town, but I’ll see if I can work up an example for you here pretty shortly. I think I might have something like this around in repo.

Hey, @arikroc So not sure if this what you’re looking to do, but it’s a fairly simple approach.

├── content
│ └── best-tools.md

---
title: "Best Tools"
layout: best-tools
---

├── layouts
│ └── page
│ └── best-tools.html


{{ define "main" }}
  {{$tools := where (where .Site.RegularPages "Section" "tool") ".Params.category" "best"}}
  {{range $tools}}
  //stuff here
  {{end}}
{{ end }}

This assumes a few things. 1) Your theme uses template inheritance (this is the define "main" part), and 2) you have a category “best” but of course that can be anything.

Keep in mind that if your tools are in the tool directory you’ll still have a tool list page and I don’t think you can alias a list page in Hugo. But this will get you the page you want.

Hope that helps!

@budparr Thank you so much. This is extremely helpful. I’ll work on this again soon, and can give you an update as to how it goes!

1 Like

It’s not necessarily clear from the diagram, but the best-tools layout is inside of the page folder

Thanks :slight_smile:

Works! Thank you again Bud!

For anyone else who finds this thread later on, I had to make some slight mods to get it to work:

I did some printf debugging, as it initially wasn’t loading, which revealed that I think the selection query was the cause - in printf, the pages showed Section as “” Type as “tools” and category as an array

So I changed the $tools := line to:

{{$tools := where .Site.RegularPages "Type" "tools"}}

And the page then loads great.

@arikroc I don’t think that’s right. If your tools are in the tool folder they should be in the section tool If it’s working for you, fine, but I’m mentioning it because it sounds like something might not be right somewhere in your code/setup.

Ok thank you, I will try and reproduce

hugo new site budparr-site

cd budparr-site

hugo new tool/toolone.md

---
title: "Toolone"
date: 2017-11-04T10:47:38-07:00
categories: [ "best" ]
---

hugo new tool/tooltwo.md

---
title: "Tooltwo"
date: 2017-11-04T10:47:41-07:00
categories: [ "best" ]
---

hugo new best-tools.md

---
title: "The Best Tools!"
url: "/best-tools/"
layout: best-tools
---

cd themes && git clone https://github.com/spf13/hyde && cd …/

mkdir layouts/page/ && touch layouts/page/best-tools.html

{{ define "main" }}
<div class="post">
  {{$tools := where (where .Site.RegularPages "Section" "tool") ".Params.category" "best"}}
  {{range $tools}}
  <span><a href="{{ .Permalink }}">{{ .Title }}</a> <time class="pull-right post-list">{{ .Date.Format "Mon, Jan 2, 2006" }}</time></span>
  {{end}}
</div>
{{ end }}

config.toml

baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "hyde"

Then /best-tools/ works but nothing shows up.

If I modify best-tools.html to the following:

{{$toolsa := where .Site.RegularPages "Section" "tool" }}
{{range $toolsa}}
  <li>
<span><a href="{{ .Permalink }}">{{ .Title }}</a> <time class="pull-right post-list">{{ .Date.Format "Mon, Jan 2, 2006" }}</time></span>
  </li>
  {{ printf "%#v" . }}
{{end}}

Then I get the two tools and their associated debug information, which contains:

"categories":[]string{"best"}

I wonder, would “.Params.category” “best” need to be modified to check for inclusion in the array?