# 为匿名用户隐藏侧边栏一部分

**URL:** <https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019>\
**Category:** Development\
**Tags:** sidebar\
**Created:** [2023年六月1日 18:04 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019 "2023-06-01T18:04:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayelen\_Rives](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ayelen_rives/32/226978_2.png) [@Ayelen\_Rives](https://meta.discourse.org/u/Ayelen_Rives)\
**Post date:** [2023年六月1日 18:04 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/1 "2023-06-01T18:04:23Z")

</div>

您好！我不确定这里是否是提问的地方，但我需要为匿名用户隐藏侧边栏的某个部分，而 CSS 代码不起作用。

我将以下 CSS 添加到 CSS 中，以隐藏匿名用户的“社区”部分：

```css
.anon div.sidebar-section-community {
     display: none;
}

```

随着 Discourse 的最新更新，现在它公开显示了，并且还显示了我添加的仅供登录用户使用的自定义部分。

您知道这段 CSS 是正确的吗？我是否遗漏了什么？

提前感谢！

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年六月1日 18:15 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/2 "2023-06-01T18:15:12Z")

</div>

> [@Ayelen\_Rives](#):
>
> ```plaintext
> .anon div.sidebar-section-community {
> display: none;
> }
> 
> ```

给你：

通用 CSS

```scss
// * 隐藏侧边栏中匿名用户的社区部分*

.anon .sidebar-section-wrapper.sidebar-section[data-section-name="community"] {
    display: none;
}

```

应该能够对您想隐藏的任何其他部分执行相同的操作，以防止匿名用户看到。

编辑：我修复了“none”之前的一个空格

* * *

顺便说一句，如果您想隐藏侧边栏中安全类别项目符号上的所有锁定徽章，您可以这样做：

```scss
// * 关闭侧边栏中所有安全类别的锁定图标*

.sidebar-section-link-wrapper .sidebar-section-link-prefix.icon .prefix-badge, .sidebar-section-link-wrapper .sidebar-section-link-prefix.span .prefix-badge {
   display: none;
}

```

---

<div class="post-metadata">

**Author:** ![Ayelen\_Rives](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ayelen_rives/32/226978_2.png) [@Ayelen\_Rives](https://meta.discourse.org/u/Ayelen_Rives)\
**Post date:** [2023年六月1日 18:46 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/3 "2023-06-01T18:46:18Z")

</div>

谢谢你的回答！  
出于某种奇怪的原因，它不起作用，无论是使用社区还是自定义 🥲

你提到的关于锁徽章的其他事情很有趣，但不确定它是否适用于我的网站配置。我会试试的。

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年六月1日 19:40 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/4 "2023-06-01T19:40:59Z")

</div>

我在我的网站上进行了现场测试，效果完美 🤷‍♀️

 ![IMG_3449](https://global.discourse-cdn.com/meta/original/4X/b/a/2/ba24d36fe7cbe3a92fdc0d0d49f446f6411634e7.jpeg)

匿名用户视图：

 ![IMG_3447](https://global.discourse-cdn.com/meta/original/4X/b/0/e/b0ee510054242d07df5601de3323cd9b8f546db5.jpeg)

已登录的普通用户视图：

 ![IMG_3448](https://global.discourse-cdn.com/meta/original/4X/0/c/b/0cb50f667adc0850a925eca55384d9226fd6cee1.jpeg)

我也在 Meta 上进行了测试。

开发者工具：

 ![scss_no_community](https://global.discourse-cdn.com/meta/original/4X/c/d/1/cd1caf910b1f54a3b5a364b5c5ccaf93903524f1.png)

侧边栏匿名用户视图：

 ![no_community](https://global.discourse-cdn.com/meta/original/4X/9/4/0/9407c0e3557ff471eaab5640344f68abe9f3684a.png)

我还测试了其他几个部分，如类别和消息，以及我的一项自定义设置。只需确保部分名称拼写正确且全部为小写。

---

<div class="post-metadata">

**Author:** ![Ayelen\_Rives](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ayelen_rives/32/226978_2.png) [@Ayelen\_Rives](https://meta.discourse.org/u/Ayelen_Rives)\
**Post date:** [2023年六月2日 12:53 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/5 "2023-06-02T12:53:24Z")

</div>

太棒了！我真的很感谢你的帮助！

我尝试这样做：

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/5/b/c5b95f59a0ab20f21c1695d542793aa27b3cb504.png)

但它仍然显示“Community”对“anon”可见：

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/5/d/85d8cd220c5192b7e2e10973cd4065875e43873b.png)

它还显示了我为公开停用的自定义部分“¿Cómo se usan?”。 🤷‍♀️

我认为一定是在别的地方出了问题。由于我是新手，我猜不到是什么，但我会继续寻找。

非常感谢！！

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年六月2日 13:07 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/6 "2023-06-02T13:07:26Z")

</div>

hmm looking at those screenshots, i suspect it may be a language thing. if you want, you can pm me your forum address and i will have a look.

---

<div class="post-metadata">

**Author:** ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)\
**Post date:** [2023年六月2日 13:08 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/7 "2023-06-02T13:08:29Z")

</div>

或者不。它在芬兰网站上运行得很好。

---

<div class="post-metadata">

**Author:** ![Ayelen\_Rives](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ayelen_rives/32/226978_2.png) [@Ayelen\_Rives](https://meta.discourse.org/u/Ayelen_Rives)\
**Post date:** [2023年六月2日 13:09 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/8 "2023-06-02T13:09:50Z")

</div>

你说得对！我把 community 改成了 comunidad，然后就好了！！  
🙌 😍

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年六月2日 13:13 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/9 "2023-06-02T13:13:14Z")

</div>

太好了！很高兴能帮到你 🙂

---

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [2023年六月2日 15:07 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/10 "2023-06-02T15:07:51Z")

</div>

我有点不明白为什么这会起作用，因为在我的任何论坛中，section 属性都是 `data-section-name="community"`，无论它们使用何种语言 🤔

@Jagster 也说在他的论坛上它就是这样工作的，而无需翻译 `data-section-name` 的值。

有人知道原因吗？

---

<div class="post-metadata">

**Author:** ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)\
**Post date:** [2023年六月2日 15:11 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/11 "2023-06-02T15:11:18Z")

</div>

我什么都不知道，但如果直接编辑英语术语而不是目标语言，会发生什么？

我的意思是，我已经编辑了芬兰语翻译，但我可以不处理它，直接编辑默认的英语翻译。

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年六月2日 15:12 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/12 "2023-06-02T15:12:55Z")

</div>

> [@Canapin](#):
>
> I’m a bit puzzled by why this works because the section attribute is `data-section-name="community"` in any of my forums, whatever the language they use 🤔

是的，如果社区是通过文本替换而不是翻译来更改的，我认为这可能会有所不同。我记得我以前在玩这个的时候，我注意到我必须将文本替换改回 community 才能使其工作，或者使用我替换成的任何文本。但是，我不知道这里是否是这种情况。

---

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [2023年六月2日 15:16 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/13 "2023-06-02T15:16:30Z")

</div>

哦，这真是个非常有趣的消息。谢谢！

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年六月2日 15:23 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/14 "2023-06-02T15:23:37Z")

</div>

确保数据部分名称正确很重要。例如，如果替换的文本包含空格（如我的论坛），则需要将其替换为连字符，并且全部小写（例如：我的网站我将“Community”替换为 CFL Forums，scss 数据部分名称为“cfl-forums”，如果我想隐藏它）。数据部分名称基本上是“slugs”。

```scss
// * 从匿名用户那里隐藏侧边栏中的任何部分 - “部分名称” = section-name * //

.anon .sidebar-section-wrapper.sidebar-section[data-section-name="section-name"] {
    display: none;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2023年七月2日 15:24 UTC](https://meta.discourse.org/t/hide-a-section-of-the-sidebar-for-anon/267019/15 "2023-07-02T15:24:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
