Request: House Ads Plugin

我再次想到了这个请求,结果发现现在无需插件,通过使用主题组件即可轻松实现。

在主题上方放置广告,并在每 3 篇帖子后放置广告的代码如下:

<script type="text/x-handlebars" data-template-name="/connectors/topic-above-post-stream/my-house-ads">
<div style="margin-bottom:10px;">
  <a href="http://www.discourse.org/buy">
    专为您的 Discourse 提供的托管服务!
  </a>
</div>
</script>

<script type="text/discourse-plugin" version="0.8.23">
    api.decorateWidget('post:after', helper => {
        let post = helper.getModel();
        if (post.get('post_number') % 3 === 0) { // 每 3 篇帖子后
            return helper.rawHtml(`
<div style="margin-bottom:10px">
  <a href="http://www.discourse.org/buy">
    专为您的 Discourse 提供的托管服务!
  </a>
</div>
            `);
        }
    });
</script>
14 个赞