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

**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:** Product Support\
**Created:** [2021 年10 月 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:** 1\
**Showing post:** 10

<div class="post-metadata">

作者： ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)\
发布日期： [2021 年10 月 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;
}

```

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

---

_[View the full topic](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)._
