# How to hide topics of multi categories and their all sub-categories from latest page

**URL:** https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416
**Category:** Feature
**Created:** [25.Январь.2015 09:45:23 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416 "2015-01-25T09:45:23Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![suanfazu](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@suanfazu](https://meta.discourse.org/u/suanfazu)
#### Post date: [25.Январь.2015 09:45:23 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/1 "2015-01-25T09:45:23Z")

</div>

I want exclude topics of several categories and their sub categories. I read the post: [https://meta.discourse.org/t/can-i-hide-a-category-from-the-latest-page/6728](https://meta.discourse.org/t/can-i-hide-a-category-from-the-latest-page/6728)  
but that does not work.

```plaintext
latest,-category1,-category2

```

this does not work?

---

<div class="post-metadata">

### Author: ![suanfazu](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@suanfazu](https://meta.discourse.org/u/suanfazu)
#### Post date: [25.Январь.2015 13:53:25 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/2 "2015-01-25T13:53:25Z")

</div>

I read the code and found the it does not support this. So I just wrote some code for this. Demo: [suanfazu.com](http://suanfazu.com/)

Usage:

```plaintext
latest,-category1:category2:subcategory1:subcategory2

```

Code below (i’m totally new to Ruby, this is my first ruby code):

```plaintext
root@suanfazu:/var/www/discourse# git diff 
diff --git a/app/models/top_menu_item.rb b/app/models/top_menu_item.rb
index 302a264..8e8d079 100644
--- a/app/models/top_menu_item.rb
+++ b/app/models/top_menu_item.rb
@@ -48,7 +48,7 @@ class TopMenuItem
   def initialize_filter(value)
     if value
       if value.start_with?('-')
- value[1..-1] # all but the leading -
+ value[1..-1].split(':') # all but the leading -
       else
         Rails.logger.warn "WARNING: found top_menu_item with invalid filter, ignoring '#{value}'..."
         nil
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index fe6d8e8..33fb001 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -276,7 +276,15 @@ class TopicQuery
 
       result = apply_ordering(result, options)
       result = result.listable_topics.includes(:category)
- result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category]).references(:categories) if options[:exclude_category]
+# result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category]).references(:categories) if options[:exclude_category]
+ if options[:exclude_category]
+ if options[:exclude_category].kind_of?(Array)
+ result = result.where('categories.name is null or categories.name not in (?)', options[:exclude_category])
+ else
+ result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category])
+ end
+ result = result.references(:categories)
+ end
 
       # Don't include the category topics if excluded
       if options[:no_definitions]

```

---

<div class="post-metadata">

### Author: ![suanfazu](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@suanfazu](https://meta.discourse.org/u/suanfazu)
#### Post date: [25.Январь.2015 14:00:15 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/3 "2015-01-25T14:00:15Z")

</div>

And looks there’s a bug here and it’s very easy to repro:

1. on home page, click to any category to navigate to the category page
2. click the top logo to go to home page, and you can still see the topics of excluded categories

and on IE, get an error saying /latest.json?exclude\_category=category1:category2 cannot be loaded because of internal server error, but there’s no error log in admin logs.

(and when you refresh the page, the topics will be loaded correctly again)

```plaintext
服务器错误

无法载入 /latest.json?exclude_category=category1:category2 

错误代码：500 Internal Server Error 

返回 再试一次 

```

hope someone could fix this. @codinghorror

---

<div class="post-metadata">

### Author: ![suanfazu](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@suanfazu](https://meta.discourse.org/u/suanfazu)
#### Post date: [25.Январь.2015 14:25:27 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/4 "2015-01-25T14:25:27Z")

</div>

I think I found the reason: my category name is in Chinese.

This request just fails:

[http://suanfazu.com/latest.json?exclude\_category=some\_chinese\_category\_name\_中文](http://suanfazu.com/latest.json?exclude_category=some_chinese_category_name_%E4%B8%AD%E6%96%87)

on IE i got 500 error  
on Chrome the filter does not work at all

@codinghorror, please fix it, seems a bug

---

<div class="post-metadata">

### Author: ![suanfazu](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@suanfazu](https://meta.discourse.org/u/suanfazu)
#### Post date: [25.Январь.2015 14:42:49 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/5 "2015-01-25T14:42:49Z")

</div>

I just made a workaround (code below). Not sure if this may cause other problems. @codinghorror please help to fix

```plaintext
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb
index bea0f7c..cb2df7a 100644
--- a/app/controllers/list_controller.rb
+++ b/app/controllers/list_controller.rb
@@ -237,7 +237,8 @@ class ListController < ApplicationController
     options = {
       page: params[:page],
       topic_ids: param_to_integer_list(:topic_ids),
- exclude_category: (params[:exclude_category] || select_menu_item.try(:filter)),
+ # exclude_category: (params[:exclude_category] || select_menu_item.try(:filter)),
+ exclude_category: (select_menu_item.try(:filter) || params[:exclude_category]),
       category: params[:category],

```

---

<div class="post-metadata">

### Author: ![walker](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@walker](https://meta.discourse.org/u/walker)
#### Post date: [21.Октябрь.2016 01:16:31 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/6 "2016-10-21T01:16:31Z")

</div>

hey!! I would like to have the exact feature and I’m working with Chinese now. Any way to do this?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [21.Октябрь.2016 01:51:36 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/7 "2016-10-21T01:51:36Z")

</div>

Today there is an option in the category settings dialog to hide from latest.

---

<div class="post-metadata">

### Author: ![walker](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@walker](https://meta.discourse.org/u/walker)
#### Post date: [21.Октябрь.2016 02:43:23 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/8 "2016-10-21T02:43:23Z")

</div>

really? is it new? Where is it? Can you post a picture?

This is the setting page of one of my categories

 ![](https://global.discourse-cdn.com/meta/original/3X/3/8/388a1d087b03430d7bb193d65e8edf50673ff3a2.png)

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [21.Октябрь.2016 02:49:50 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/9 "2016-10-21T02:49:50Z")

</div>

If latest is set as your homepage, you want to use Suppress this category from the homepage

---

<div class="post-metadata">

### Author: ![walker](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@walker](https://meta.discourse.org/u/walker)
#### Post date: [21.Октябрь.2016 02:57:52 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/10 "2016-10-21T02:57:52Z")

</div>

Thanks for you reply!!

I still want this category in the category list, not suppressing it, just not in the latest page. Is it possible?

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [21.Октябрь.2016 02:58:29 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/11 "2016-10-21T02:58:29Z")

</div>

What is set as your homepage? If it is Latest, that is exactly what that setting should do.

---

<div class="post-metadata">

### Author: ![walker](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@walker](https://meta.discourse.org/u/walker)
#### Post date: [21.Октябрь.2016 03:08:30 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/12 "2016-10-21T03:08:30Z")

</div>

no, the homepage is category. and I select categories with latest topics

 ![](https://global.discourse-cdn.com/meta/original/3X/9/6/962d05737646bfdaa5d14c16ccaa761bfeb7fa77.png)

now it’s like this

 ![](https://global.discourse-cdn.com/meta/original/3X/c/d/cdfe3520ad1c1825a2fdb330c242ef64bb2cb6ec.png)

I like it, just I want to hide certain categories from the right column

sorry for the Chinese

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [21.Октябрь.2016 03:18:19 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/13 "2016-10-21T03:18:19Z")

</div>

Unfortunately, it doesn’t seem to do that, it removes it from the left side, not the right side (which leaves this as a feature request).

---

<div class="post-metadata">

### Author: ![walker](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@walker](https://meta.discourse.org/u/walker)
#### Post date: [21.Октябрь.2016 03:23:42 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/14 "2016-10-21T03:23:42Z")

</div>

Hey I suddenly find a setting “mute category”. Does this help?

 ![](https://global.discourse-cdn.com/meta/original/3X/d/6/d6c65bf038ddf19160dfef406981adc18095464c.png)

what does this mean? all topics in a category will be muted and muted topics will not be shown in the latest? I added those categories I would live to hide from LATEST, but it doesn’t work. How can I tag a topic with muted tag?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [21.Октябрь.2016 03:27:19 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/15 "2016-10-21T03:27:19Z")

</div>

I fnd it a bit odd that on the newer hybrid category page, the tags have an empty class value.

```plaintext
<tr data-topic-id="51825" class="">
      <td class="topic-poster">

```

A to-do that got forgotten?

---

<div class="post-metadata">

### Author: ![walker](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@walker](https://meta.discourse.org/u/walker)
#### Post date: [21.Октябрь.2016 03:31:11 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/16 "2016-10-21T03:31:11Z")

</div>

not really understand this. T\_T

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [21.Октябрь.2016 03:32:22 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/17 "2016-10-21T03:32:22Z")

</div>

Just that if the class value contained a category name. CSS could be used to display: none them.

---

<div class="post-metadata">

### Author: ![walker](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@walker](https://meta.discourse.org/u/walker)
#### Post date: [21.Октябрь.2016 03:36:43 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/18 "2016-10-21T03:36:43Z")

</div>

oh really… quite sad if this can’t be done

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [21.Октябрь.2016 03:42:38 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/19 "2016-10-21T03:42:38Z")

</div>

> [@walker](#):
>
> quite sad if this can’t be done

Yes, I find CSS fixes are often the easiest approach. For example, this found in “Suggested” below. If for some reason it was decided to not show topics in the “feature” category, it would be trivial to not display the row.

```plaintext
<div id="suggested-topics">
.....
<tr id="ember3635"
 class="ember-view topic-list-item category-feature"
 data-topic-id="38733">

```

To be fair, getting the code to put a category name in the class value may not be so easy.

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [04.Декабрь.2025 11:33:30 UTC](https://meta.discourse.org/t/how-to-hide-topics-of-multi-categories-and-their-all-sub-categories-from-latest-page/24416/20 "2025-12-04T11:33:30Z")

</div>


