# 隐藏特定类别从主页没有静音或如何获取新主题计数在静音类别中

**URL:** https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196
**Category:** Support
**Created:** [2022 年3 月 6 日 12:22 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196 "2022-03-06T12:22:20Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 12:22 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/1 "2022-03-06T12:22:20Z")

</div>

我的社区在一个特定类别下发布了太多主题。

有时人们会觉得烦人，并希望将其从主页移除。  
但是，即使是这些用户也并非对这些类别完全不感兴趣，也不想使用静音来完全阻止它们。

因此，我提出了两种方法。  
1：在主页上放置一个复选框，用于选择是否显示特定类别。  
2：不静音该类别，而是在主页上显示静音类别中的新主题数量。用户可以通过点击添加到导航栏的特定类别选项卡立即看到该类别。

事实上，我可以在方法2中显示新主题的数量，但在组件完成后不久，我发现我无法获取静音类别中的新主题数量……我忘记检查静音类别了……

所以，我接下来正在考虑方法1，但我不知道主页查询是如何工作的，也不知道如何隐藏某些类别……

或者，方法2的解决方案（如何获取静音类别中的新主题数量）也可以。

任何帮助都将不胜感激。

---

<div class="post-metadata">

### Author: ![4ong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/4ong/32/186618_2.png) [@4ong](https://meta.discourse.org/u/4ong)
#### Post date: [2022 年3 月 6 日 14:58 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/2 "2022-03-06T14:58:14Z")

</div>

你好 @Programer-D  
你可以尝试 [GitHub - keegangeorge/discourse-hide-categories: This is a theme component that allows you to hide specific categories from either the hamburger menu or category boxes.](https://github.com/keegangeorge/discourse-hide-categories)  
或者使用 CSS 的方式。

---

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 16:38 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/3 "2022-03-06T16:38:18Z")

</div>

非常感谢。

CSS 曾是我的盲点，但我尝试了一些方法，但似乎效果不佳。  
我不是英语母语者，所以我想我解释得不够清楚。  
在 1 中，通知必须设置在“正常”之下，并且某些类别必须隐藏。  
在 CSS 中，我可以获取类别类并隐藏它，但这似乎也会删除“Watching”和“Tracking”… 我将尝试找到一种方法，根据每个主题的通知设置来赋予类。

此外，我做了一些研究，似乎大约两年前，从顶部移除类别的功能曾引起激烈争论，后来被移除并被“静音”取代。

我认为那些反对将其完全替换为静音的人是对的。“静音”是一个很棒的功能。但“正常”和“静音”之间的差距太大了，“静音”会让类别远远落后。  
如果能有另一个通知设置，在两者之间会更好。

我会再仔细考虑一下……

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022 年3 月 6 日 16:40 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/4 "2022-03-06T16:40:56Z")

</div>

我认为有一个插件可以复制旧的“suppress”行为，如果这有帮助的话？

> **[GitHub - discourse/discourse-categories-suppressed](https://github.com/discourse/discourse-categories-suppressed)**
>
> Contribute to discourse/discourse-categories-suppressed development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 16:43 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/5 "2022-03-06T16:43:38Z")

</div>

非常感谢。  
我刚才在看一个旧的讨论话题，里面提到了创建这样一个插件，我当时正在找它。  
我一有空就会试试。

---

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 17:36 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/6 "2022-03-06T17:36:07Z")

</div>

总之，默认情况下似乎会隐藏所有通知设置的显示。  
这仍然是可行的（尽管事后看来，CSS 也不错），但我会尝试完善它，看看是否可以仅隐藏普通和静音通知设置。

由于这是一个插件，似乎还有改进的空间，所以我又恢复了一点动力。非常感谢。

---

<div class="post-metadata">

### Author: ![4ong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/4ong/32/186618_2.png) [@4ong](https://meta.discourse.org/u/4ong)
#### Post date: [2022 年3 月 6 日 19:02 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/7 "2022-03-06T19:02:30Z")

</div>

“\>我不是英语母语者

你的母语是什么？如果是俄语/乌克兰语，欢迎私信联系我。  
我今晚会更详细地检查你的问题。”

---

<div class="post-metadata">

### Author: ![4ong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/4ong/32/186618_2.png) [@4ong](https://meta.discourse.org/u/4ong)
#### Post date: [2022 年3 月 6 日 19:06 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/8 "2022-03-06T19:06:57Z")

</div>

还有一个想法——将此类别仅限于特定组，并让用户在需要时加入该类别。  
或者默认加入，并在用户不想再看到它时停止参与该组。

您还可以[为不同组编辑 CSS](https://github.com/discourse/discourse-groups-css-classes-in-body)——例如，可以有一个按钮轻松加入该组。

---

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 19:44 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/9 "2022-03-06T19:44:33Z")

</div>

我研究了一下这个插件，看起来并不容易……我看了 `result = Topic::ActiveRecord` 里面，似乎不包含任何与通知相关的数据。

此外，我想知道是否可以从这里获取单个主题的信息并获得 `notification_level`。  
我创建过涉及一些 Ruby 的插件，但主要依赖 JavaScript，所以对 Ruby 不太了解。

也许……我想遍历 `result` 的内容来获取每个主题的详细信息，只记录 `notification_level` 为“Tracking”或“Watching”的主题的 ID 到列表中，并在 `where` 子句中添加“OR topics.topic\_id IN (#{topic\_ids.join(‘,’)})”。我知道这代码不太优雅，而且我对 Ruby 不熟悉，所以不确定它是否能正常工作……

我将去寻找一种从 Ruby 调用 Topic by ID 的方法。

---

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 19:48 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/10 "2022-03-06T19:48:01Z")

</div>

非常感谢。  
我没想过要使用群组……但如果当前的插件修改不起作用，我会考虑一下。

---

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 20:48 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/11 "2022-03-06T20:48:38Z")

</div>

我完全不明白，但不知怎么的它奏效了。

万一还有其他人想做同样的事情，我把它留在这里。

我从 [JammyDodger](https://meta.discourse.org/u/JammyDodger) 那里学到的插件的 `plugin.rb` 文件第 17 行。

> **[GitHub - discourse/discourse-categories-suppressed](https://github.com/discourse/discourse-categories-suppressed)**
>
> Contribute to discourse/discourse-categories-suppressed development by creating an account on GitHub.

```plaintext
result.where("topics.category_id NOT IN (#{category_ids.join(",")})")

```

改为

```plaintext
result.where("topics.category_id NOT IN (#{category_ids.join(",")}) OR tu.notification_level IN (2,3)")

```

“跟踪”和“关注”主题仍然显示在首页上，但“普通”主题则从首页隐藏。  
这花了我一些时间，因为我没有正确理解 ActiveRecord，但如果我能正确地沟通问题，对你来说可能是一个简单的问题。

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022 年3 月 6 日 20:57 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/12 "2022-03-06T20:57:01Z")

</div>

我不确定我是否完全理解，但如果您从 `default categories muted` 管理员设置中“默认静音”一个类别，听起来这已经做了类似的事情？主题不会出现在“最新”列表中，但如果转到类别页面，所有主题都是可见的。如果用户与某个主题互动，使其变为“跟踪”或“关注”，那么这些主题就会显示在他们的主题列表中。

这是否就是您想要的？

---

<div class="post-metadata">

### Author: ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)
#### Post date: [2022 年3 月 6 日 21:13 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/13 "2022-03-06T21:13:30Z")

</div>

静音大致满足了要求，但有一个问题：它不再获取新主题。

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/b/2bf847f56dc5984160c426b387007cc16f271f8b.png)

我创建了一个组件来获取此主题计数，但意识到静音无法获取新主题计数，因为静音主题未计入新主题。

我创建了一个组件来获取此主题计数，但我注意到静音无法获取新主题，因此我无法获取新主题的数量。

这就是为什么我一直在寻找一种方法，通过“正常”通知设置来阻止它出现在首页。

这可能是一种特殊情况。对于给定的类别，首页上有大量未读主题，而默认静音会使新主题难以被注意到，并导致用户过度远离该类别。我们不希望这样做，因为首页上有大量主题意味着一个非常活跃的类别。

也许这是一个应该通过用户教育来解决的问题，但我们还是想尽力而为，很高兴我们设法满足了要求。

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022 年3 月 7 日 07:07 UTC](https://meta.discourse.org/t/hide-specific-categories-from-the-top-page-without-muted-or-how-to-get-new-topic-count-in-muted-category/220196/14 "2022-03-07T07:07:53Z")

</div>

啊，我想我明白了。很高兴你找到了适合你的解决方案。👍🙂
