# 筛选收藏夹

**URL:** https://meta.discourse.org/t/filter-favorites/386594
**Category:** Theme component
**Tags:** topic-filter
**Created:** [2025年十月24日 01:02 UTC](https://meta.discourse.org/t/filter-favorites/386594 "2025-10-24T01:02:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2025年十月24日 01:02 UTC](https://meta.discourse.org/t/filter-favorites/386594/1 "2025-10-24T01:02:58Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **摘要** | 允许用户保存他们喜欢的过滤器，并可选择定义默认过滤器 |
| 👓 | **预览** | [Theme Creator](https://discourse.theme-creator.io/theme/Moin/favorite-filter)  
⚠ 该组件使用现有的自定义用户字段作为年龄输入。在测试完可定制性后，您可能希望在偏好设置中清除该字段。 |
| 🛠 | **仓库** | [GitHub - moin-Jana/favorite-filter: Allow users to save their favorite filters and optionally define default filters](https://github.com/moin-Jana/favorite-filter) |
| ❓ | **安装指南** | [如何安装主题或主题组件](https://meta.discourse.org/t/how-do-i-install-a-theme-or-theme-component/63682) |
| 📖 | **不熟悉 Discourse 主题？** | [Discourse 主题使用入门指南](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) |

安装此主题组件

**Favorite Filters** 在主题过滤器上方添加了可自定义的过滤器快捷方式。管理员可以提供默认过滤器按钮，用户可以创建和自定义他们自己的收藏过滤器。

 ![主题过滤器上方的一些过滤器按钮](https://global.discourse-cdn.com/meta/original/4X/9/b/6/9b68f7821d73c0676b6f9c592dc03a55ba9f2a62.png)

要将当前应用的过滤器保存到您的收藏夹，请点击星形图标，输入标签，并可选择选择一个图标或表情符号。

 ![添加收藏过滤器模态框](https://global.discourse-cdn.com/meta/original/4X/0/f/e/0fe4694fed160948f8ac7b65587c47a521eb66db.png)

您还可以更改排序、删除和编辑您当前的收藏夹

 ![编辑过滤器收藏模态框](https://global.discourse-cdn.com/meta/original/4X/8/2/d/82dc20306d4f0d13ec73ee7d73c91fc41bb9cd61.png)

### 配置

#### 自定义过滤器

主题组件无法在数据库中创建新字段，因此要允许用户保存他们喜欢的过滤器，您需要创建一个自定义用户字段来存储此信息。因此，

- 打开用户字段配置。您可以在管理员侧边栏的社区部分找到它。
- 点击“添加用户字段”。
- 选择“文本”作为字段类型，并输入字段名称和描述。
- 将字段留空（可选）。
- 启用注册后的编辑，但不要在任何地方显示它。

> **配置截图**
>
> ![自定义用户字段配置](https://global.discourse-cdn.com/meta/original/4X/4/d/8/4d8d327e686a629cb699f1b3bb7b22d32e4741d9.png)

保存用户字段后，点击编辑按钮并检查 URL。它看起来会像 `/admin/config/user-fields/12/edit`。数字是用户字段的 ID。这就是您要输入到组件的 **`custom user field ID`** 设置中的内容。该组件将隐藏用户字段在用户个人资料偏好设置中的显示，以防止无效输入。

您还可以选择使用 **`custom favorite filters allowed groups`** 设置将创建和保存收藏过滤器的权限限制在特定的用户组。

#### 默认过滤器

配置默认过滤器的最简单方法是使用过滤器 UI 将它们创建为您自己的过滤器收藏夹，并将用户字段中的值插入到设置中。因此，您可以取消隐藏管理员用户的偏好设置中的用户字段（ **`show for admin`** ）。

然后，您可以将用户字段的内容复制到 **`default favorites`** 设置中。

默认过滤器也可以通过 **`default favorite filters groups`** 限制在特定组。例如，如果许多过滤器对未注册用户不起作用（因为他们没有书签或无法访问某些类别），则此功能非常有用。同样，您可以为管理员配置特定的过滤器作为默认值，而普通用户可以创建自己的收藏过滤器，而无需看到与他们无关的默认值。

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [2025年十月24日 13:53 UTC](https://meta.discourse.org/t/filter-favorites/386594/2 "2025-10-24T13:53:09Z")

</div>

这看起来真棒，Moin！

---

<div class="post-metadata">

### Author: ![patrickemin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/patrickemin/32/520162_2.png) [@patrickemin](https://meta.discourse.org/u/patrickemin)
#### Post date: [2025年十月25日 00:38 UTC](https://meta.discourse.org/t/filter-favorites/386594/3 "2025-10-25T00:38:03Z")

</div>

我轻松地就位了，这真是太棒了！

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2025年十月25日 05:40 UTC](https://meta.discourse.org/t/filter-favorites/386594/4 "2025-10-25T05:40:52Z")

</div>

> [@Moin](#):
>
> 它会是类似 `/admin/config/user-fields/12/edit` 的形式

这是一个有趣的解决方法。我一直希望能为“用户主题设置”构建第一方支持，那样的话你就不需要这个了。我喜欢你找到了绕过这个限制的方法。

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2025年十月25日 06:53 UTC](https://meta.discourse.org/t/filter-favorites/386594/6 "2025-10-25T06:53:15Z")

</div>

谢谢。但这并非我的主意。这个问题以前已经以这种方式解决过好几次了。我能想到的相关主题有：

> [@Our solution for blurring NSFW content](https://meta.discourse.org/t/our-solution-for-blurring-nsfw-content/124584):
>
> At the Blender Artists forum we have a faily liberal content policy where we allow nudity and violence (up to a point). While most members are fine with this kind of content, there are of course audiences and situations where this is not suitable (for us mainly schools and children). And since we make heavy use of tiled galleries with the [Topic List Preview plugin](https://meta.discourse.org/t/topic-list-previews/101646), we needed a way to make this kind of content opt-in and get it out of your face by default. The solution was easier to implement th…

> [@User preference on theme components](https://meta.discourse.org/t/user-preference-on-theme-components/191268/2):
>
> Create a Custom User Field then use it in your theme component.

> [@Sidebar User Field Toggle](https://meta.discourse.org/t/sidebar-user-field-toggle/257634/2):
>
> Thank you, @Lhc_fl, for quick and quality solution. Our use case is based on our [marketplace request’s description](https://meta.discourse.org/t/user-custom-field-toggle-for-sidebar-sfw-mode/257342): The idea was inspired by [Our solution for blurring NSFW content](https://meta.discourse.org/t/our-solution-for-blurring-nsfw-content/124584), we just started by inverting the logic and needed a toggle for our community to blur & unblur media. Just add Custom User Field as a Checkbox and follow our approach below. We use Sidebar User Field Toggle with additional custom component like so: Create new theme component right within your admin dashboard /ad…

> [@User customizable theme components (how-to)](https://meta.discourse.org/t/user-customizable-theme-components-how-to/345240):
>
> On my [forum](https://forum.magicball.net/) I wanted give the users some customization options on the default theme. I wanted to give them the option to set a background for the forum. I could make different themes for this, but that is quite a bit of extra work. And while themes do have settings, these are for everybody and not specifically for a user. But there is a way to achieve user configurable settings for themes, and that is by “abusing” [user fields](https://meta.discourse.org/t/creating-and-configuring-custom-user-fields/113192). In my theme the user has actually 3 settings for the wallpaper (imag…
