我能更改主标志的URL吗?

For example, let’s say I wanted the logo to point to forum.example.com/latest instead of forum.example.com, how would I do that? Is that something I can change easily without needing a developer? Discourse is hosting my forum, if that makes any difference.

The reason I want that is because I want my default forum page when someone goes on the forum to be the “Categories” page so the forum is less intimidating. But I want them to go on the “Latest” page once they click on the logo.

This should work in a theme:

<script type="text/discourse-plugin" version="0.4">
    api.changeWidgetSetting('home-logo', 'href', '/latest')
</script>
3 个赞

Thanks! Since I’m a noob, could you specify where to paste this? I assume it’s not where the CSS goes?

Goes into the HEAD section to the right of the CSS one. You can learn about it on Developer’s guide to Discourse Themes

4 个赞

抱歉打扰,但如何让它在新标签页中打开而不是在当前标签页中打开?target="_blank" 在这里可用吗?

这需要更多的自定义,因为它在此处的 home-logo 小部件中被阻止:

所以您必须使用 changeWidgetSetting 来设置 URL,然后使用 reopenWidget 来添加 _blank 并覆盖阻止在新窗口中打开的默认单击行为。

<script type="text/discourse-plugin" version="0.8">
  const { h } = require("virtual-dom");

  api.changeWidgetSetting('home-logo', 'href', 'https://discourse.org');

  api.reopenWidget("home-logo", {
     html() {
       return h(
         "a",
         { attributes: { href: this.href(), "data-auto-route": true, "target": "_blank" } },
         this.logo()
       );
     },

     click(e) {
       return;
     },
   });
</script>
4 个赞

感谢您出色的解释。我通过在标题中添加一个图标链接,并将其 URL 设置为我想要的徽标指向的位置,并在另一个选项卡中打开,找到了一个解决方法。它奏效了,最终为用户提供了他们想要的(在标题中链接到外部主站点)。个人而言,我更喜欢它目前的样子,因为我喜欢使用徽标作为我的论坛主页链接。

2 个赞