Forums

[resolved] hiding pages from non-members (11 posts)

  1. lashman
    Member
    Posted 2 years ago #

    hi,

    I was wondering - is there any way (native or a plugin) to hide a certain page from non-registered users? let's say I've got a "tutorials" page and I don't want it to be visible at all (or at least in the website navigation menu) until the user registers and logs in (regardless of the role specified for that user) ... is that possible?

    regards,
    martin

  2. MichaelH
    Volunteer
    Posted 2 years ago #

  3. lashman
    Member
    Posted 2 years ago #

    hi,

    yeah ... I've searched all those tags and I've seen the plugin you've given me link to already ... but the thing is - those don't make the page invisible ... they just display a login form on that page ... and I want to make the page invisible in the menu navigation for non-members ... I don't really care if it could be found through the search field or accessed through a direct link to it ... I just want to make it invisible as long as the user isn't logged in.

    regards,
    martin

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    The something like this for where you display your list of pages:

    <?php
    if (is_user_logged_in()){
        wp_list_pages('title_li=<h2>Pages</h2>' );
    }
    else {
        wp_list_pages('exclude=7&title_li=<h2>Pages</h2>' );
    };
    ?>

    Replace the 7 in the exclude=7 with your page id.

  5. lashman
    Member
    Posted 2 years ago #

    hi,

    thanks ... looking at this piece of code - it should help ... but I'm fairly new to WP ... could you tell me where exactly to put this code?
    oh, and by the way - if it matters anything - I'm currently using the Mystique theme.

    regards,
    martin

  6. MichaelH
    Volunteer
    Posted 2 years ago #

    Could put that in a theme's sidebar.php, or if you are using Widgets consider downloading and installing Otto's PHP Code Widget then put the code in one of those widgets.

  7. lashman
    Member
    Posted 2 years ago #

    hi,

    hmmm ... yeeees ... but what if my navigation is horizontal and I don't want tu put additional navigation in the sidebar? as in: http://multi-studio.pl/portfolio ...

    regards,
    martin

  8. MichaelH
    Volunteer
    Posted 2 years ago #

    Then you probably will want to change your theme's header.php to incorporate that.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  9. lashman
    Member
    Posted 2 years ago #

    hi,

    (just to be sure) but the code remains the same? or what? I'm really new to WP ... not to mention - almost complete PHP-noob ......

    regards,
    martin

  10. MichaelH
    Volunteer
    Posted 2 years ago #

    In that theme's header.php change:

    echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a class="fadeThis"$2><span class="title">$3</span><span class="pointer"></span></a>', wp_list_pages('echo=0&orderby=name&title_li=&exclude='.get_mystique_option('exclude_pages')));

    to

    if (is_user_logged_in()){
                     echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a class="fadeThis"$2><span class="title">$3</span><span class="pointer"></span></a>', wp_list_pages('echo=0&orderby=name&title_li=&exclude='.get_mystique_option('exclude_pages')));
    }
    else {
                     echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a class="fadeThis"$2><span class="title">$3</span><span class="pointer"></span></a>', wp_list_pages('echo=0&orderby=name&title_li=&exclude=2,'.get_mystique_option('exclude_pages')));
    };
    
               endif;

    The key is this exclude=2,43,67, where the 2,43,67, are the IDs of the pages being hidden from users that are NOT logged in. Note those ID's are appended in front of the exclude ability that theme offers.

    And just in case:
    How do I determine a Post, Page, Category, Tag, Link, Link Category, or User ID?

  11. lashman
    Member
    Posted 2 years ago #

    hi,

    oh ... great :) it works like a charm!! :) thanks a lot :) there was just one thing I had to change ... you told me to write:

    if (is_user_logged_in()){
                     echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a class="fadeThis"$2><span class="title">$3</span><span class="pointer"></span></a>', wp_list_pages('echo=0&orderby=name&title_li=&exclude='.get_mystique_option('exclude_pages')));
    }
    else {
                     echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a class="fadeThis"$2><span class="title">$3</span><span class="pointer"></span></a>', wp_list_pages('echo=0&orderby=name&title_li=&exclude=2,'.get_mystique_option('exclude_pages')));
    };
    
               endif;

    whereas I actually had to change it a bit ... to:

    if (is_user_logged_in()):
                     echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a class="fadeThis"$2><span class="title">$3</span><span class="pointer"></span></a>', wp_list_pages('echo=0&orderby=name&title_li=&exclude='.get_mystique_option('exclude_pages')));
    
    else:
                     echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a class="fadeThis"$2><span class="title">$3</span><span class="pointer"></span></a>', wp_list_pages('echo=0&orderby=name&title_li=&exclude=2,'.get_mystique_option('exclude_pages')));
    
               endif;

    regards,
    martin

Topic Closed

This topic has been closed to new replies.

About this Topic