Hoe de functie van inloggen om inhoud te bekijken te implementeren, om gebruikers beter te werven voor registratie

As the title suggests, I searched the forum and only found how to change the security of categories, but this only makes all categories invisible, which is not the functionality I need.

My use case is: unregistered users can view some post content, and hidden content can only be viewed after logging in. Or registered users need to reply to the post to view it.

This is a means to attract registrations and also to prevent most leechers.

Similar to

1 like

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

As mentioned in the question, I searched in the forum and only found the security of changing categories, but this will only make all categories invisible, which is not the function I need.

My usage scenario is: unregistered users can view a portion of the post content, while hidden content can only be viewed by logging in. Alternatively, to register as a user, you need to reply to the post in order to view it.

This is a means of attracting registration and also preventing the majority of reaching out parties.

Similar to:

1 like

Is what you are asking for similar to what a lot of news papers do? For example, as an anonymous user, I can view the front page and category pages of the New York Times:

If I then try to visit an article, I’m shown something like this:

The reason I am asking in this way is because I think the idea has been mentioned on this forum a few times. I like the idea. It might be useful to show that this is a common way that subscription based publications get users to subscribe. The idea might be useful for some Discourse sites - especially sites that are trying to attract paid subscribers.

2 likes

Does this theme component do what you want to achieve?

3 likes

Yes, simon,because my website will have many software download links, but I don’t want unregistered users to see it and click it.thank you for your reply!

I would really like it if it was like spoiler mode.—> download links When an unregistered user clicks, a registration pop-up window or payment pop-up window will appear, which will be very elegant.

“Unable to view content without replying”–Active users selflessly share their knowledge and they want more responses to their posts. This is also what the forum owners want. I think this feature is beneficial to the development of the forum.

I will try using this plugin.thank you,lilly!

2 likes

You’re welcome, I hope it works for you. Just note that it is a theme component and not a plug-in, so you can install it from the admin UI.

1 like

I think the Gated Topics in Category theme component is doing the same. :slightly_smiling_face:

4 likes

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 ( Composer tip under specific tag topics ) that determines whether you have replied. If you have a programming background, you can take a look at what I wrote. Combined with the decorateCookedElement method of the API, it can be implemented to hide content when not replied to.

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: "This post is hidden";
}
`

api.addPostClassesCallback((attrs) => {
if (attrs?.cooked?.includes(`div data-theme-hide="true"`)) {
  return ["hiddened"]; // For adding CSS, how you write the CSS next is up to you
} 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>Post hidden by community</p>`; // Modify this line
            hide_post();
        }
    }, {
        id: pid,
        afterAdopt: true,
        onlyStream: true,
    });
}


</script>

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

4 likes

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