# 如何为所有用户设置相同的侧边栏分类

**URL:** https://meta.discourse.org/t/how-to-set-the-same-sidebar-categories-for-all-the-users/402479
**Category:** Site Management
**Tags:** sidebar
**Created:** [2026年五月11日 07:59 UTC](https://meta.discourse.org/t/how-to-set-the-same-sidebar-categories-for-all-the-users/402479 "2026-05-11T07:59:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [2026年五月11日 07:59 UTC](https://meta.discourse.org/t/how-to-set-the-same-sidebar-categories-for-all-the-users/402479/1 "2026-05-11T07:59:06Z")

</div>

有时，站点管理员需要确保所有用户在侧边栏中看到相同的类别集。以下是操作方法：

- 从 `default navigation menu categories` 中移除所有类别并保存。当被提示时，请确保将更改历史性地应用。
- 等待几分钟。
- 将所有希望所有用户显示的类别添加到 `default navigation menu categories`。同样，当被提示时，请确保将更改历史性地应用。

“历史性地应用”意味着将此更改应用于现有用户，同时为未来加入的用户设置默认值。当您看到以下模态框时，需要点击 `Yes`：

 ![Screenshot 2026-05-08 at 6.51.17 PM](https://global.discourse-cdn.com/meta/original/4X/b/2/6/b263da88b75bf1f197e9a483584f7cb127b9e5bb.png)

**注意：此设置不会使没有访问权限的用户看到私有类别。**

---

<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: [2026年五月11日 09:20 UTC](https://meta.discourse.org/t/how-to-set-the-same-sidebar-categories-for-all-the-users/402479/2 "2026-05-11T09:20:12Z")

</div>

> [@fzngagan](#):
>
> - 从“默认导航菜单类别”中移除所有类别并保存。如果系统提示，请确保历史性地应用此更改。
> - 等待几分钟。

一次性移除之前的默认设置并添加新设置，与分两步进行（中间间隔一段时间）有什么区别？

我曾短暂认为这个过程会重置所有个性化自定义。但根据我的测试，事实并非如此。如果某个类别之前不在侧边栏的默认设置中，而是由用户自行添加的，那么即使清除了设置，它也不会被移除。只有之前在设置中配置的类别会被移除。

因此，若要使所有人的侧边栏保持一致，你需要执行以下步骤：

- 将所有类别添加到设置中（并且最好不要为所有人覆盖此设置）
- 然后从设置中移除所有类别，并为所有人覆盖此设置
- （等待几分钟？）
- 添加新的类别，并为所有人覆盖此设置

此处需要将步骤 2 和步骤 4 分开，因为步骤 1 并未应用到所有人身上。我们可以将步骤 1 应用到所有人，使所有人的侧边栏都包含所有类别，几分钟后，再移除我们不希望出现在他们侧边栏中的类别。但这可能会导致几分钟内用户体验变差。

我的测试（显示清除手动添加类别的设置不会被移除）是否不正确？步骤分离是否有其他原因？我想了解这一点，以便决定是否需要将相关信息添加到 [Configuring the default sidebar for your users](https://meta.discourse.org/t/configuring-the-default-sidebar-for-your-users/347764#p-1690272-categories-section-6%E3%80%82)

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [2026年五月13日 15:38 UTC](https://meta.discourse.org/t/how-to-set-the-same-sidebar-categories-for-all-the-users/402479/5 "2026-05-13T15:38:17Z")

</div>

@Moin  
这里的回填（backfilling）工作方式与通常的预期略有不同。当更新“默认导航菜单类别”设置时，我们并不会简单地重置所有用户的侧边栏类别。我们的做法如下：

- 如果管理员在设置中添加了一些类别，那么只有这些新添加的类别会被加入到尚未设置这些类别的所有用户的侧边栏中。
- 如果从设置中移除了某些类别，那么这些类别也会从所有用户的侧边栏中移除。

因此，回填并不会强制将设置的状态应用到所有用户，而是仅对设置中新增或移除的类别进行增量更新。

这样做的主要原因是为了保留每个用户的个人偏好。

引入此行为的 PR 如下：

> <https://github.com/discourse/discourse/pull/18620>
>
> The previous sidebar default tags and categories implementation did not
> allow f…or a user to configure their sidebar to have no categories or
> tags. This commit changes how the defaults are applied. When a user is being created,
> we create the SidebarSectionLink records based on the \`default\_sidebar\_categories\` and
> \`default\_sidebar\_tags\` site settings. SidebarSectionLink records are
> only created for categories and tags which the user has visibility on at
> the point of user creation.
> 
> With this change, we're also adding the ability for admins to apply
> changes to the \`default\_sidebar\_categories\` and \`default\_sidebar\_tags\`
> site settings historically when changing their site setting. When a new
> category/tag has been added to the default, the new category/tag will be
> added to the sidebar for all users if the admin elects to apply the changes historically.
> Like wise when a tag/category is removed, the tag/category will be
> removed from the sidebar for all users if the admin elects to apply the
> changes historically.
> 
> Internal Ref: /t/73500

我们曾尝试通过以下两种方式使所有用户拥有相同的类别：

1. 全部添加，按历史应用；再移除部分，按历史应用。
2. 全部移除，按历史应用；再添加部分，按历史应用。

在最近一次针对大型站点的尝试中，方法 1 未能正常工作，而方法 2 则成功了。因此我记录了方法 2。

如果您有时间，请尝试用一批用户测试这两种方式，看看是否有效。如果需要，我可以编写一个 SQL 查询来确认更新是否按预期生效。请随时告诉我您的想法。

---

<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: [2026年五月14日 22:56 UTC](https://meta.discourse.org/t/how-to-set-the-same-sidebar-categories-for-all-the-users/402479/6 "2026-05-14T22:56:55Z")

</div>

> [@fzngagan](#):
>
> 如果您有时间，请尝试用一批用户测试这两种方法，看看是否有效。如果需要，我可以编写一个 SQL 查询来确认更新是否按预期生效。请告诉我您的想法。

我再次尝试了您在第一篇文章中描述的步骤。但我仍然注意到同样的问题：用户添加到其侧边栏的类别并未被移除，因此结果并非所有用户在其侧边栏中都拥有相同的类别。

> **详细复现步骤**
>
> 1. 我创建了一个全新的论坛
> 2. 我创建了 5 个类别（category1、category2、category3、category4、category5）
> 3. 我使用“编辑侧边栏类别”选项将 `category4` 添加到了我的侧边栏  
> ![image](https://global.discourse-cdn.com/meta/original/4X/6/8/6/68627bdc28b0625b32fc3d6c2239b958b3559405.png)  
> ![image](https://global.discourse-cdn.com/meta/original/4X/8/0/0/80003f56a0d79dbe023068f6f94ca7a57a06b68f.png)
> 4. 该类别已添加到我的侧边栏  
> ![image](https://global.discourse-cdn.com/meta/original/4X/1/2/0/1208caee3960b5728d2eecae49945abba56db5f1.png)
> 5. 我查看了 `default_navigation_menu_categories` 站点设置  
> ![image](https://global.discourse-cdn.com/meta/original/4X/7/7/6/776f83007fd70e787b28e83f83f75d7fbd80d81c.png)
> 6. 正如您在指南中所说，我移除了所有类别
> 
> > [@fzngagan](#):
> >
> > 从 `default navigation menu categories` 中移除所有类别并保存。当被提示时，请确保将更改历史性地应用。
> 
> ![image](https://global.discourse-cdn.com/meta/original/4X/b/0/0/b0084306ec92ac05139c939646e7099fe5fc5f4e.png)  
> 并将更改应用给所有用户  
> ![image](https://global.discourse-cdn.com/meta/original/4X/5/8/c/58cb1a69bd437b4d9722faeb7e0f78fc998aeb47.png)  
> 7. 现在该设置已为空  
> ![image](https://global.discourse-cdn.com/meta/original/4X/2/2/5/2250fb81a94c827414c3f1cde73eeab7e209b705.png)  
> 8. 我检查了我的侧边栏，只有手动添加的 `category4` 在其中（底部的站点设置链接也表明该站点设置已为空）  
> ![image](https://global.discourse-cdn.com/meta/original/4X/a/2/2/a220d44bbcbd6c74a4070dd548dd8a0701b53897.png)  
> 9. 我等待了约 45 分钟，然后将 `category1`、`category2` 和 `category3` 添加到了设置中  
> ![image](https://global.discourse-cdn.com/meta/original/4X/5/f/8/5f888ffc717f84f3d411666de329b9e342b3cbe1.png)  
> 并将更改应用给所有用户  
> ![image](https://global.discourse-cdn.com/meta/original/4X/1/3/a/13ae6f3f2d1761a3c690b6bdd42733719def2fb2.png)  
> ![image](https://global.discourse-cdn.com/meta/original/4X/6/9/e/69e521f07bb7317c597ac2c3234a19304e88e6fa.png)
> 
> **基于本指南标题的预期结果** ：所有用户在其侧边栏中都拥有相同的类别，即仅包含设置中的类别，不包含其他内容。  
> **实际结果** ：`category4` 仍然在侧边栏中，而对于未手动添加该类别的用户，其侧边栏中并没有它。
> 
> ![image](https://global.discourse-cdn.com/meta/original/4X/4/7/b/47b692686f221efb9dc3c045fea86e990b175f70.png)

您期望在哪个步骤中移除用户手动添加到其侧边栏的类别（在我的例子中是 `category4`），从而实现所有用户侧边栏中拥有相同类别的结果？

> [@fzngagan](#):
>
> - 如果管理员向设置中添加几个类别，只有那些新添加的类别会被添加到尚未设置这些类别的所有用户的侧边栏中。
> - 如果您从设置中移除几个类别，这些类别将从所有用户的侧边栏中移除。

根据您在这里所说的，我预期它不会被移除，因为该类别并未从设置中移除，因为它本来就不在设置中。但您说您使用这些步骤来强制所有用户拥有相同的类别。  
如果我添加了所有类别（方法 1），`category4` 将会被添加然后被移除，所以我预期它会消失。这就是我理解发生的情况的地方。但您的指南说我应该使用方法 2，所以我想知道我在理解或测试中遗漏了什么。
