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; $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 } ?>
</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)).