Hiding paid members posts

Hi -

is there a way not to show paid members’ post excerpt to either free members and/or public? In other words, if a post is for paid members anyone with lower access levels wouldn’t even know the post exists.

Thank you!

Hey @Vitalik :wave:

That’s totally possible with the use of custom collections and routes. We’ve written up a method of doing so in our docs, where you can create custom collections that filter out your paying content from your main site collection:

Hope this helps!

Thanks, David - I’ll take a look.

1 Like

Hi @Vitalik,
if you want to completely hide posts from being shown on your page, depending on the user level, you could use something like this.

(I tested it in the lyra theme, which is based on casper):
Basically if you’re a paid member, you can see every post
(visibility="all")
If you’re a member, you can see the public and the members content (visibility="public,members")
If you’re a public visitor, you can only see public content.
(visibility="public")

{{#if @member.paid}}
        {{#foreach posts visibility="all"}}
        {{> "post-card"}}
        {{/foreach}}
    {{else}}
        {{#if @member}}
        {{#foreach posts visibility="public,members"}}
        {{> "post-card"}}
        {{/foreach}}
    {{else}}
        {{#foreach posts visibility="public"}}
        {{> "post-card"}}
        {{/foreach}}
    {{/if}}
{{/if}}

Let me know if you need help.

1 Like

Side note to @daniel1’s technique, this may cause issues with pagination. Defining proper collection pages will ensure pagination will work as expected :+1:

Thanks, Daniel and David. For now, I went with Daniel’s solution because, honestly, I could not figure out how to make a single “/:” collection work for three different levels with the same logic as in Daniel’s post: if @member.paid - show all posts, if @member - show public and members, and just public otherwise. Maybe it’s not possible with one collection and three collections would be necessary instead. But than there is additional complexity of directing users to proper collection depending on their access level.

The difference between my method and Daniel’s is that mine would create different pages that list different posts based on their visibility, whereas Daniel’s show/hide posts depending on their visibility level on the same page. Really depends on what you’re going for :blush: