# 在主页显示所有分类（包括已静音的），但不在最新帖子中显示其主题

**URL:** <https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435>\
**Category:** Support\
**Created:** [2021年十月19日 13:53 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435 "2021-10-19T13:53:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)\
**Post date:** [2021年十月19日 13:53 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/1 "2021-10-19T13:53:27Z")

</div>

因此，我们的主页显示两列：左侧为分类，右侧为最新话题。

某一分类中的话题会自动更新，因此我希望在右侧列（最新）中隐藏该分类。

但我不想对所有用户静音该分类——在主页的“已静音”（即折叠/ spoiler）区域中隐藏它看起来非常糟糕。

有什么方法可以绕过这个问题吗？

---

<div class="post-metadata">

**Author:** ![manuel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/manuel/32/468169_2.png) [@manuel](https://meta.discourse.org/u/manuel)\
**Post date:** [2021年十月19日 14:02 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/2 "2021-10-19T14:02:20Z")

</div>

> **[GitHub - communiteq/discourse-suppress-category-from-latest](https://github.com/communiteq/discourse-suppress-category-from-latest)**
>
> Contribute to communiteq/discourse-suppress-category-from-latest development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)\
**Post date:** [2021年十月19日 14:55 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/3 "2021-10-19T14:55:21Z")

</div>

上次更新约在 2 年前。我担心可能存在兼容性问题。

最理想的情况是能够通过标准方法实现我的目标。

---

<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:** [2021年十月19日 15:02 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/4 "2021-10-19T15:02:53Z")

</div>

考虑创建一个子类别，并将父类别设置为默认列表过滤器中不包含子类别的主题？

---

<div class="post-metadata">

**Author:** ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)\
**Post date:** [2021年十月19日 15:03 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/5 "2021-10-19T15:03:58Z")

</div>

> [@JammyDodger](#):
>
> 并将父类别设置为在默认列表过滤器中不包含子类别的主题？

这会影响“最新”列表在“类别+最新”主页中的显示吗？

---

<div class="post-metadata">

**Author:** ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)\
**Post date:** [2021年十月19日 15:07 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/6 "2021-10-19T15:07:45Z")

</div>

另一个问题是，如果某人屏蔽了某个分类，这不会影响向匿名用户显示的内容，对吗？

在我的情况下，我希望实现一致性。我需要一个功能完整的分类，其行为与正常分类相同，只是其新主题和更新不会在首页的“最新”中显示。

---

<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:** [2021年十月19日 15:14 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/7 "2021-10-19T15:14:44Z")

</div>

> [@meglio](#):
>
> 这会影响“最新”列表在分类 + 最新主页上的显示吗？

老实说，如果不镜像您的设置，我也不确定。🙂 不过，您也可以将子分类默认设为静音（或者在安全设置中更改可见性）。您可能需要尝试几种组合，看看哪种能接近您的需求。

> [@meglio](#):
>
> 另一个问题是，如果有人静音了某个分类，这不会影响匿名用户看到的内容，对吧？

如果用户静音了某项内容（主题、分类、标签或其他用户），这仅对该用户生效，不会影响其他人。

您需要在管理员设置中使用默认静音选项来使其全局生效，但即使如此，用户也可以覆盖这些设置。

---

<div class="post-metadata">

**Author:** ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)\
**Post date:** [2021年十月19日 15:39 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/8 "2021-10-19T15:39:09Z")

</div>

没错。所以我才来这里——因为在我能想到的几种变通方法都尝试过后，仍无法解决这个问题。

---

<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:** [2021年十月19日 16:07 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/9 "2021-10-19T16:07:21Z")

</div>

拥有一个常规父类别和一个默认静音的子类别，似乎能接近您的需求？

或者，使用静音标签是否更合适？

---

<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:** [2021年十月19日 17:12 UTC](https://meta.discourse.org/t/show-all-categories-in-the-home-page-including-muted-ones-but-dont-show-its-topics-in-the-latest-posts/206435/10 "2021-10-19T17:12:15Z")

</div>

该视图默认显示 20 个主题。因此，除非该特定类别有大量主题被置顶（无论是新主题还是回复），否则我认为直接隐藏这些主题就可以了。

你有两个选择。

1. 在你的主题头部标签中使用 JavaScript

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

  api.modifyClass("component:categories-topic-list", {
    @on("didReceiveAttrs")
    removeCategoryTopics() {
      const filtered = this.topics.filter(
        ({ category_id }) => category_id !== ignoreCategoryId
      );

      this.topics = filtered;
    },
  });
</script>

```

这将完全阻止主题标记的渲染。将 `ignoreCategoryId` 更改为你想要针对的类别 ID。你可以通过访问该类别并检查浏览器中的 URL 来找到该 ID。

```plaintext
https://meta.discourse.org/c/support/6 <---- 最后一位数字是类别 ID

```

1. 使用 CSS… 如果是顶级类别

```css
.latest-topic-list-item.category-SLUG {
  display: none;
}

```

如果是子类别

```css
.latest-topic-list-item.category-PARENT_SLUG-CATEGORY_SLUG {
  display: none;
}

```

据我所知，超出此范围的任何操作都需要插件或对核心进行修改。
