如何为仅登录用户在标题中添加按钮?我需要为该按钮添加自定义文本和链接。
您是否已搜索 Theme component 类别,看看是否已存在符合您需求的内容?
这是一个很棒的解决方案,
我其实只想在顶部放一个按钮。
我最终的做法是问 ChatGPT 如何手动添加代码,它给了我一个可行的解决方案……
Header:
<script type="text/discourse-plugin" version="0.8.22">
api.decorateWidget('header-buttons:after', helper => {
let currentUser = api.getCurrentUser();
if (!currentUser) return;
return helper.h('li.custom-login-button-li', [
helper.h('a.custom-login-button', { href: 'ENTER URL HERE', target: '_blank'}, 'Button')
]);
});
</script>
CSS
.custom-login-button {
display: inline-block;
margin: 0;
padding: 0.5em 1em;
text-align: center;
vertical-align: middle;
border: 1px solid transparent;
font-weight: bold;
line-height: 1.5;
border-radius: 3px;
color: #fff !important;
background-color: #0084ff;
border-color: #0076e6;
text-decoration: none;
cursor: pointer;
transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}
.custom-login-button:hover {
background-color: #0076e6;
border-color: #0065d0;
}
.custom-login-button-li {
list-style-type: none;
}
干得好@Sami_Syed。
我在论坛上为仅限移动用户使用一个图标而使用了上面的图标链接TC。