hiding pages from non-members
-
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
-
Look at:
http://wordpress.org/extend/plugins/pagerestrict/generic:
* http://wordpress.org/extend/plugins/tags/restriction
* http://wordpress.org/extend/plugins/tags/restrict
* http://wordpress.org/extend/plugins/tags/members
* http://wordpress.org/extend/plugins/tags/membership
* http://wordpress.org/extend/plugins/tags/register
* http://wordpress.org/extend/plugins/tags/registrationhi,
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,
martinThe 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.
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,
martinCould 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.
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,
martinThen you probably will want to change your theme’s header.php to incorporate that.
Related:
Stepping Into Template Tags
Stepping Into Templates
Template Hierarchyhi,
(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,
martinIn 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?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
- The topic ‘hiding pages from non-members’ is closed to new replies.