WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How can I create a members' only area? (10 posts)

  1. Hermiony
    Member
    Posted 6 years ago #

    Hi,:-)

    I've searched the forums but haven't found an answer to this.

    I want some areas of my site to be visisble to everyone, but also a specific password-protected area where members can have access to discussion, calendar of events, photos etc. I would like them to only have to put their password in once per visit, otherwise I would just password-protect each individual page.

    Does anyone know how I can do this?

  2. levani0101
    Member
    Posted 6 years ago #

    It's one of the most necessary function which WordPress doesn't allow, unfortunately.

  3. Hermiony
    Member
    Posted 6 years ago #

    Hi, thanks for your reply. I searched some more and it does look as if it is doable, although it looks like advanced skills are needed.

    See below:

    I wanna make a site where you have to login to view. is this something that's built into wordpress or is there a plug-in for it?

    Posted 12 months ago #
    doodlebee
    Member
    I know of two solutions for this. Someone else might come along with better ideas, too...but...

    1) Use your .htaccess file to password-protect your wordpress directory. Then only people you pass the username and password to can visit the site. Everyone else will get a "Forbidden" error page. This is not a WordPress thing - you have to edit/create your own .htaccess files to do this.

    2) Install WordPress in a subdirectory, but place index.php outside of the installation, one level up. Make it a static page. Leave only the "login" link of your Meta section on the static page. People who come to your site will see the static page, and can't go any further into the site unless they log in. This can be done solely with WordPress code, but it's most certainly advanced theme editing to get it done.

    Like I said, there may be other options, but those are the two I know of.

    Posted 12 months ago #
    </strong>

  4. Kalessin
    Member
    Posted 6 years ago #

    A simpler method may be to password protect the individual posts and pages to which you want to restrict access, from the edit screen. However, this would have to be maintained on an item-by-item basis which is perhaps a bit cumbersome for your needs.

  5. Hermiony
    Member
    Posted 6 years ago #

    Hi Kalessin,

    Yes, I'd thought about that but my feeling is that it wouldn't be so user-friendly as people would need to keep putting the password in as they navigate around.

    Also, I really need an events calendar and I haven't found a way of having one directly on a page, rather than in the sidebar, so I don't think that would work for a password-protected page.

    I'm a bit surprised that there isn't a simple way of doing it.

    :-)

  6. Steven Jones
    Member
    Posted 6 years ago #

    Couldn't you just create a different template that had a conditional statement before the content to only show if the user is logged in and then if they aren't say "Must be logged into view this"?

    Steve

  7. Steven Jones
    Member
    Posted 6 years ago #

    Just to back up my point something like this for a template to replace a normal page template.

    <?php get_header(); ?>

    <div id="content" class="narrowcolumn">
    <IF LOGGED IN THEN>

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
    <div class="entry">
    <?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>

    <?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

    </div>
    </div>
    <?php endwhile; endif; ?>
    <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    </div>

    <ELSE>

    <p> Please login </p>

    <CLOSE IF STATEMENT)

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

    I've not looked at any of the cookies so I don't quite know what the <IF LOGGED IN THEN> would comprise of but surely that would work? Again it's just the first thing that came to my head.

    Cheers,
    Steve

  8. Kalessin
    Member
    Posted 6 years ago #

    That's nice, didn't think of that. The bit that is missing (the if-then statement) goes like this:

    <?php
    global $userdata
    get_currentuserinfo() ;
    if ( $userdata->user_level == 2 )
    {
      echo 'User is an Author';
    }
    else
    {
      echo 'User is not an Author';
    }
    ?>
  9. noelgreen
    Member
    Posted 6 years ago #

    The easiest way to do this is by using the WordPress Password Plugin. I use it on one of my sites and it works great!

  10. Hermiony
    Member
    Posted 6 years ago #

    Hi,

    Thanks everyone for your help and suggestions. I'm not yet experienced enough to add code to templates etc but am trying the plugin. Noel, are you able to tell me your url so I can see it in action?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags