# Filter Content Pages by Category Using Taxonomies

**URL:** <https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697>\
**Category:** support\
**Created:** [August 3, 2017, 8:09pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697 "2017-08-03T20:09:46Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 8:09pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/1 "2017-08-03T20:09:46Z")

</div>

I’m attempting to list the names of .md files on a certain page. They must match a certain category (seen below). However, I want the place of the category below (visualdesign) to change based on what the current page title is. For instance, the page that this code is located on is called “Tabs”, I want the category in the code below to change to “tabs”. I’ve tried `{{ .Title }}` in the place of `.visualdesign`. Though, I receive an error in my terminal and half of the live webpage disappears.

**Here’s the code (located in /layouts/\_default/single.html):**

```
<div id="block-menu">
          <a href="/Workforce-StyleGuide/" class="top" style="font-weight: bold;">{{ .Title }}</a><br>
          {{ range first 100 .Site.Taxonomies.categories.visualdesign}}
               <a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a><br>
          {{ end }}
</div>

```

Any thoughts on how I could get this to work?

Thanks!

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 8:25pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/2 "2017-08-03T20:25:40Z")

</div>

@guayom I’ve seen you mention some taxonomy things before in the threads. Is this something you’ve encountered or worked with before?

---

<div class="post-metadata">

**Author:** ![guayom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/guayom/32/3732_2.png) [@guayom](https://discourse.gohugo.io/u/guayom)\
**Post date:** [August 3, 2017, 8:25pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/3 "2017-08-03T20:25:56Z")

</div>

I was just dealing with this problem. You want to dynamically filter taxonomies.  
You can find how to do it on [this post](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697)

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 8:27pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/4 "2017-08-03T20:27:00Z")

</div>

@guayom Lol I wrote that post.

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 8:30pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/5 "2017-08-03T20:30:58Z")

</div>

@guayom I’ve been trying to set this up as a variable, but I don’t think that will work `{{$pageTitle := .Title}}`

---

<div class="post-metadata">

**Author:** ![guayom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/guayom/32/3732_2.png) [@guayom](https://discourse.gohugo.io/u/guayom)\
**Post date:** [August 3, 2017, 8:33pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/6 "2017-08-03T20:33:32Z")

</div>

Lol, sorry, I messed up. [Here](https://discourse.gohugo.io/t/solved-dynamically-filter-pages-by-taxonomy/7679/29)

Try that approach. It works and it’s easy. I’ll try to post a very detailed post about this later today, in case you have any doubts.

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 8:36pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/7 "2017-08-03T20:36:33Z")

</div>

No worries man. Thanks for getting back to me. Yeah, I’m a little unsure about that. Hard to find a solution.

---

<div class="post-metadata">

**Author:** ![guayom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/guayom/32/3732_2.png) [@guayom](https://discourse.gohugo.io/u/guayom)\
**Post date:** [August 3, 2017, 8:45pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/8 "2017-08-03T20:45:50Z")

</div>

Yeah, it took me several hours to figure it out. For what I read in your OP I think this approach is what you’re looking for. If you read that post completely, you may find the way to achive what you’re looking for. Specially [this post](https://discourse.gohugo.io/t/solved-dynamically-filter-pages-by-taxonomy/7679/26?u=guayom)  
Or hang in there for my post in tips and tricks

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 9:31pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/9 "2017-08-03T21:31:44Z")

</div>

Okay, thank you for your help. Do you know if it possible to grab just the categories or tags from just the page you are viewing?

---

<div class="post-metadata">

**Author:** ![guayom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/guayom/32/3732_2.png) [@guayom](https://discourse.gohugo.io/u/guayom)\
**Post date:** [August 3, 2017, 9:49pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/10 "2017-08-03T21:49:25Z")

</div>

Sure, you an access them through `.Params.categories`

You can list them as shown [here in the docs](https://gohugo.io/templates/taxonomy-templates/#display-a-single-piece-of-content-s-taxonomies)

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 9:52pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/11 "2017-08-03T21:52:53Z")

</div>

Hmm, yeah I’ve tried that. However I receive an error in the Terminal:

`ERROR 2017/08/03 17:52:19 Error while rendering "page": template: theme/_default/single.html:51:18: executing "theme/_default/single.html" at <.Params.tags>: range can't iterate over test`

The same also applies if I do `.Params.categories`

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 10:14pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/12 "2017-08-03T22:14:29Z")

</div>

Actually, I got that working. Yet the output is in lowercase. I’m looking up a way to grab the title from the category.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [August 3, 2017, 10:16pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/13 "2017-08-03T22:16:51Z")

</div>

You can use the title function to convert them to title case. See here: [https://gohugo.io/functions/title/#readout](https://gohugo.io/functions/title/#readout)

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 10:19pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/14 "2017-08-03T22:19:27Z")

</div>

Very cool. I’m doing `{{title . | urlize }}`. Would I have to specify using `{{ .Title }}`?

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [August 3, 2017, 10:22pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/15 "2017-08-03T22:22:54Z")

</div>

You are doing it fine. `{{ .Title }}` refers to the title of a Page. You said above that you’re getting Categories.

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 10:24pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/16 "2017-08-03T22:24:17Z")

</div>

Strange, still is lowercase using `{{title . | urlize }}`.

---

<div class="post-metadata">

**Author:** ![guayom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/guayom/32/3732_2.png) [@guayom](https://discourse.gohugo.io/u/guayom)\
**Post date:** [August 3, 2017, 10:31pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/17 "2017-08-03T22:31:22Z")

</div>

Urlize makes everything lowercase

---

<div class="post-metadata">

**Author:** ![anon22990659](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon22990659](https://discourse.gohugo.io/u/anon22990659)\
**Post date:** [August 3, 2017, 10:34pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/18 "2017-08-03T22:34:13Z")

</div>

Is there another way to grab the title of the category? Like `.Page.Title`?

… Can’t post more that x-number of replies my first day on here 😉 I figured it out lol. `{{ . }}` didn’t know that was the output function. All good now. This solved my 6-hour issue. I can post my final snippet in Tips and Tricks if you’d guys like. Thanks again for all of your help 🙂

---

<div class="post-metadata">

**Author:** ![guayom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/guayom/32/3732_2.png) [@guayom](https://discourse.gohugo.io/u/guayom)\
**Post date:** [August 3, 2017, 11:04pm UTC](https://discourse.gohugo.io/t/filter-content-pages-by-category-using-taxonomies/7697/19 "2017-08-03T23:04:51Z")

</div>

Yeah, that got me too a couple times. Takes some time to get used to that.
