How to implement the function of logging in to view content, in order to better attract users to register

如题,我在论坛里搜索,只查到更改类别的安全性,但这样只会使全部类别都不可见,并不是我需要的功能。

我的使用情景是:未注册用户可以查看一部分帖子内容,隐藏部分的内容只能登录才能查看。或者注册用户,需回复帖子才能查看。

这是一个吸引注册的手段,也是防止大部分的伸手党。

类似于

1 个赞

如何实现登录查看内容的功能,以更好地吸引用户注册

正如问题中所述,我在论坛中搜索过,只找到了关于更改分类安全性的方法,但这只会使所有分类都不可见,并不是我需要的功能。

我的使用场景是:未注册用户可以查看部分帖子内容,而隐藏内容只有登录后才能查看。或者,注册用户需要回复帖子才能查看。

这是吸引注册的一种方式,也可以防止大多数“伸手党”。

类似于:

1 个赞

您所询问的是否类似于许多报纸的做法?例如,作为一个匿名用户,我可以查看《纽约时报》的头版和分类页面:

如果我尝试访问一篇文章,我会看到类似这样的内容:

我之所以这样提问,是因为我认为这个想法在本论坛上已经提到过几次了。我喜欢这个想法。它可能有助于表明这是基于订阅的出版物吸引用户订阅的常见方式。这个想法_可能_对一些 Discourse 网站有用——特别是那些试图吸引付费订阅者的网站。

2 个赞

这个主题组件能实现您想要的效果吗?

3 个赞

是的,simon,因为我的网站将有许多软件下载链接,但我不希望未注册用户看到和点击它们。谢谢你的回复!

我非常希望它能像“Spoiler”模式一样。—> 下载链接 当未注册用户点击时,会弹出一个注册窗口或付款窗口,这将非常优雅。

“回复前无法查看内容”–活跃用户无私地分享他们的知识,他们希望他们的帖子得到更多回复。这也是论坛所有者想要的。我认为这个功能有利于论坛的发展。

我会尝试使用这个插件。谢谢你,lilly!

2 个赞

不客气,希望它对你有用。请注意,它是一个主题组件,而不是插件,所以你可以从管理员界面安装它。

1 个赞

我认为 Gated Topics in Category 这个主题组件也在做同样的事情。:slightly_smiling_face:

4 个赞

这个好办啊,topic model里面有一个attribute就显示了你是否已经回复过,叫posted,我之前写了个组件 Composer tip under specific tag topics 就判断了是否已经回复过。如果你有代码基础,可以看一下我写的。结合api的decorateCookedElement方法就能实现在没回复的情况下隐藏。

具体代码我懒得写了最近特别忙。

This is easy to do. There is an attribute in the topic model that shows whether you have replied to it. It is called posted. I wrote a component before ( https://meta.discourse.org/t/composer-tip-under- specific-tag-topics/255618/1 ) determines whether you have replied. If you can program, you can take a look at what I wrote. Combined with the decorateCookedElement method of the API, it can be implemented.

I am too lazy to write the specific code. I have been very busy recently.

<script type="text/discourse-plugin" version="1.6.0">

const user = api.getCurrentUser();

const I18n = require("I18n");

const pid = "post_hider"

const tl4_css = `
.d-editor-preview [data-theme-hide] {
  background: var(--tertiary);
  color: var(--secondary);
  border-top: 2px solid var(--secondary);
  position: sticky;
  top: 0;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.d-editor-preview [data-theme-hide]::before {
  content: "本帖子被设为隐藏";
}
`

api.addPostClassesCallback((attrs) => {
if (attrs?.cooked?.includes(`<div data-theme-hide="true">`)) {
  return ["hiddened"]; // 添加css用的,接下来css怎么写看你了
} else {
  return [];
}
});

if (!user) {
    api.decorateCookedElement((el, helper) => {
        function hide_post() {
            setTimeout( () => {
                try {
                    // document.querySelector(`[data-post-id="${helper?.widget?.attrs?.id}"]`)?.parentElement?.remove();
                } catch (err) {
                    console.log(el);
                    console.log(err);
                }
            }, 1000);
        }
        if (el?.querySelector(`[data-theme-hide="true"]`)) {
            el.innerHTML = `<p>帖子已被社区隐藏</p>`; // 修改这行
            hide_post();
        }
    }, {
        id: pid,
        afterAdopt: true,
        onlyStream: true,
    });
} 


    
</script>

想起来我这里有一份之前用来给未登录用户隐藏整个帖子的代码,你可以拿来参考一下

I remembered that I have a code that I used to hide the entire post from non-logged-in users. You can use it for reference.

4 个赞

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