PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Membership only for older posts

s2Member Plugin. A Membership plugin for WordPress®.

Membership only for older posts

Postby ronhen » November 14th, 2011, 10:11 am

Hello,

Is it possible to setup S2 in way that you have to be a member to see posts of say older than one month. The newest posts must always be free for every visitor. Or will that require some extra (source)coding?

Thanks
Ron
User avatar
ronhen
Registered User
Registered User
 
Posts: 2
Joined: November 14, 2011

Re: Membership only for older posts

Postby Eduan » November 14th, 2011, 10:41 am

See if this video gives you an idea:
http://www.s2member.com/advanced-conditionals-video/

And you can sell access with levels, so level 0 (free) has access to newer posts and level 1 has access to everything.
Check this video on how to do that:
http://www.s2member.com/general-options-overview-video/

I found all these videos in this link:
http://www.s2member.com/videos/
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Membership only for older posts

Postby Raam Dev » November 14th, 2011, 10:37 pm

Hi Ronhen,

I recently did something similar with s2Member. It required modifying my single.php theme file.

What I did was check if the post was less than 30 days old. If the post is less than 30 days old *OR* the person viewing it is logged in, then display the post.

Otherwise, (if the post is older than 30 days old and the person viewing it is NOT logged in) display a message that says they need to be a member and give them a link to subscribe.

Here's an example code from my own single.php. Your theme file will look slightly different, but the concept is the same.

Code: Select all

    <div id="content">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            <h2><?php the_title(); ?></h2>

                <?php
                $restrict_after
=30 * 86400; // days * seconds per day (30 days)
                $post_age = date('U') - get_post_time('U');
                if ($post_age < $restrict_after || is_user_logged_in()) { ?>
                    <div class="entry">

                        <?php the_content(); ?>
                                
                    </div>        

                <?php }
                else { ?>
                    <div class="entry">                    

                           <p>This post is older than 30 days and can only be accessed with a <a href="http://example.com/join /">membership</a>. If you already have a membership, please <a href="http://example.com/login/">login</a> to view this post.</p>

                    </div>
                    
        <?php } // Closes if-block that checks post age ?>    
        </div> <!-- closes 'post class' -->

    <?php endwhile; else: ?>

        <p>Sorry, no posts matched your criteria.</p>

<?php endif; ?>

    </div> <!-- closes 'content' -->


As Eduan mentioned, you can also incorporate s2Member Advanced Conditionals.

For example, my code above simply checks if the visitor is logged in (is_user_logged_in()) and then lets them view the page. If you wanted to only let people with s2Member Membership Level #2 or higher to see the post, you could change that to current_user_can("access_s2member_level2").

You could also incorporate checking for specific Custom Capabilities that you've assigned the user (see WP-Admin -> s2Member -> API / Scripting -> Custom Capabilities (Packages)).
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Membership only for older posts

Postby ronhen » November 15th, 2011, 3:01 am

Thanks Raam! Figured out it had to be something like that, but the code example is very helpfull.
By the way, I wonder why this membership model (newest posts free for every visitor) isn't used more offen, because it seems an option if your website is depending on ads also.
User avatar
ronhen
Registered User
Registered User
 
Posts: 2
Joined: November 14, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron