# 如何限制对按钮钉住/解除钉住的访问

**URL:** https://meta.discourse.org/t/how-restrict-access-to-button-pin-unpin/348498
**Category:** Development
**Tags:** pinned-topics
**Created:** [2025年一月22日 21:36 UTC](https://meta.discourse.org/t/how-restrict-access-to-button-pin-unpin/348498 "2025-01-22T21:36:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![HeadShot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/headshot/32/483120_2.png) [@HeadShot](https://meta.discourse.org/u/HeadShot)
#### Post date: [2025年一月22日 21:36 UTC](https://meta.discourse.org/t/how-restrict-access-to-button-pin-unpin/348498/1 "2025-01-22T21:36:44Z")

</div>

我在页眉中尝试了此代码

```java
document.addEventListener("DOMContentLoaded", function() {
    setTimeout(() => {
        let userTrustLevel = parseInt(Discourse.User.current().trust_level);

        if (userTrustLevel < 4) {
            document.querySelectorAll(".pin-topic, .unpin-topic").forEach(button => {
                button.style.pointerEvents = "none";
                button.style.opacity = "0.5";
                button.title = "您无权置顶主题";
            });
        }
    }, 1000); complet
});

```

并在 CSS 中添加了以下代码

```css
.d-header-icons .pin-topic,
.d-header-icons .unpin-topic,
.controls .pin-topic,
.controls .unpin-topic {
    display: none !important;
}

```

但是，信任等级为 1 或 0 的普通用户仍然可以点击并看到置顶按钮。

`默认情况下，当用户滚动到底部时自动取消置顶主题。` 此选项已关闭  
`当用户滚动到底部时自动取消置顶主题。` 此选项已关闭

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2025年一月22日 22:27 UTC](https://meta.discourse.org/t/how-restrict-access-to-button-pin-unpin/348498/2 "2025-01-22T22:27:43Z")

</div>

嘿，欢迎！👋

您是在说这些按钮吗？

 ![The image shows an online post interface with options to share, bookmark, and reply, labeled under "Unpinned" and "Normal," where "Normal" is selected and displays that notifications will be provided for mentions. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/e/b/e/ebe81fe71e99bfd9d9f7ead60c56924c00fde1a4.png)

您可以使用纯 CSS 来隐藏这些按钮。

首先安装此组件：[https://meta.discourse.org/t/css-classes-for-current-users-groups/226068。它会将当前用户组名称（例如](https://meta.discourse.org/t/css-classes-for-current-users-groups/226068%E3%80%82%E5%AE%83%E4%BC%9A%E5%B0%86%E5%BD%93%E5%89%8D%E7%94%A8%E6%88%B7%E7%BB%84%E5%90%8D%E7%A7%B0%EF%BC%88%E4%BE%8B%E5%A6%82) `group-<name>`）添加到 `<body>` 元素中。

然后您可以定位任何元素：

```css
:not(.group-trust_level_4) #topic-footer-buttons .pinned-button {
  display: none;
}

```

---

<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: [2025年一月22日 23:49 UTC](https://meta.discourse.org/t/how-restrict-access-to-button-pin-unpin/348498/3 "2025-01-22T23:49:42Z")

</div>

另外，主题可以被固定/取消固定在几个地方：

- 在主题的底部，如上所述

- 在主题视图中主题标题的旁边  

- 在主题列表中的主题标题旁边

---

<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: [2025年二月21日 23:50 UTC](https://meta.discourse.org/t/how-restrict-access-to-button-pin-unpin/348498/4 "2025-02-21T23:50:26Z")

</div>

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