ログインユーザーのみを対象にヘッダーにボタンを追加するにはどうすればよいですか。このボタンにはカスタムテキストとリンクを追加する必要があります。
Theme component カテゴリで、ニーズに合うものが既に存在するかどうか検索
「いいね!」 1
ログインユーザーのみに表示する
匿名ユーザーを対象にすることで、匿名ユーザーから要素を非表示にすることができます。たとえば、これはログインしていないユーザーからナビゲーションサイドバーメニューのタグを非表示にする例です。同様のコードを使用して、ヘッダー内の任意の要素を匿名ユーザーから非表示にすることができます。
.anon .sidebar-section-wrapper.sidebar-section[data-section-name="tags"] {
display: none;
}
「いいね!」 2
これは素晴らしい解決策です。
実際には、上にボタンを1つだけ配置したかったのです。
ChatGPTにコードで手動で追加する方法を尋ねたところ、動作するソリューションが得られました…
ヘッダー:
<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;
}
「いいね!」 1
@Sami_Syed、素晴らしい仕事です。
フォーラムで、モバイルユーザー専用のアイコンとして、上記のヘッダーアイコンリンクTCを使用しています。
「いいね!」 1
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.