How to make a blog member-only (4 posts)

  1. Phasm
    Posted 6 years ago #

    I'm sure this is fairly easy but I just wanted to verify the correct way. How do you make a WordPress blog so that you have to be a member and login to view any material on it?

  2. oriecat
    Posted 6 years ago #

  3. Tommie Hansen
    Posted 6 years ago #

    Don't use plugins for things that is so easy to modify via page templates.

    Example template code:

    Template Name: Members only
    	<div id="maincontent">
    			<div class="page">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<div class="post" id="post-<?php the_ID(); ?>">
    			<h1 class="newstitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    			<div class="postcontent mt20">
    			<?php if (is_user_logged_in()) : <strong>// CRUCIAL!</strong> ?>
    			<?php the_content(__('(Read more..)')); ?>
    			<?php else : ?>
    			<div class="errorbox">
    			<h2>Sorry.</h2><p>This page requires that you are a member of this page, please log in or become a member.</p>
    			<?php endif; ?>
    			</div><!-- postcontent end -->
    			</div><!-- post end -->
    			<?php endwhile; else: ?>
    			<p><?php _e('Sorry, no posts matched your query.'); ?></p>
    			<?php endif; ?>
    			<?php posts_nav_link(' — ', __('< Previous page'), __('Next page >')); ?>
    			</div><!-- page end -->
    	</div><!-- maincontent end -->

    Tommie Hansen
    Dekorfilm.se | Mindescape Reklam

  4. Phasm
    Posted 6 years ago #

    Thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic