# Hide subcategories without hiding their topics in topic list?

**URL:** https://meta.discourse.org/t/hide-subcategories-without-hiding-their-topics-in-topic-list/195502
**Category:** Support
**Created:** [June 30, 2021, 3:05pm UTC](https://meta.discourse.org/t/hide-subcategories-without-hiding-their-topics-in-topic-list/195502 "2021-06-30T15:05:43Z")
**Posts on this page:** 1
**Showing post:** 18

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [July 7, 2021, 8:06am UTC](https://meta.discourse.org/t/hide-subcategories-without-hiding-their-topics-in-topic-list/195502/18 "2021-07-07T08:06:15Z")

</div>

Yeah, there was an issue with how the category was set that I missed locally. I edited the snippet above, and it should work now.

The snippet above allows you to set the categories you want this to work on. If you want it to work on all categories, you’d use something like this.

```javascript
<script type="text/discourse-plugin" version="0.8">
  const { on } = require("discourse-common/utils/decorators");

  const useParentCategory = function () {
    const parentCategory = this.attrs.topic.category.parentCategory;

    if (parentCategory) {
     this.attrs.topic.set("category", parentCategory);
    }
  };

  api.modifyClass("component:topic-list-item", {
    @on("didReceiveAttrs")
    setCategory() {
      useParentCategory.call(this);
    }
  });

  api.modifyClass("component:latest-topic-list-item", {
    @on("didReceiveAttrs")
    setCategory() {
      useParentCategory.call(this);
    }
  });
</script>

```

---

_[View the full topic](https://meta.discourse.org/t/hide-subcategories-without-hiding-their-topics-in-topic-list/195502)._
