I could make the two categories that need login, subjected to a php conditional line.
I saw a solution similar ( How to block a category from one user and enable the category for the rest of the users – http://wordpress.stackexchange.com/questions/21558/how-to-block-a-category-from-one-user-and-enable-the-category-for-the-rest-of-the ), but I do not have the same problem.
Basically, every one without login is able to see two of the four categories, two always hidden for every one, except teacher, who once login are able to see everything.
Any one?
I should use something like this I do imagine:
<?php if ( is_user_logged_in() ) { ... } ?>
Yes that is correct:
<?php if ( is_user_logged_in() ) { ?>
<!-- code here for what only logged in users can see -->
<?php } else { ?>
<-- code here for what users that are not logged in see e.g. a login form -->
<?php wp_login_form(); ?>
<?php } ?>
Would this work? Where do I past it?
<?php if ( (!is_user_logged_in()) && in_category('10,5') ) { ?>
You'll need to be a member to view this content.
<?php } else { ?>
<?php the_content(); ?>
<?php } ?>
Ah, the categories are 10 and 5
Where to past it depends on your theme but I would go for category.php.
I would do this:
<?php if(in_category( array( 5,10 ) ) { // if the current post is in categories 5 or 10 ?>
<?php if ( !is_user_logged_in() ) { // check whether the user is logged in ?>
<p>You'll need to be a member to view this content.</p>
<?php } else { // user is logged in so go ahead and show content ?>
<?php the_content(); ?>
<?php } ?>
<?php } ?>
My theme does not have Category.php…. hmm.
Thanks,
If it has an archive.php then do it in there, if not then index.php.
I was told the code sniped that I am using should work with this format:
<?php global $current_user; get_currentuserinfo(); if ($current_user->user_level == 10 ) { ?>
<a href="<?php echo CP_ADD_NEW_URL ?>" class="obtn btn_orange"><?php _e('Post an Ad', 'appthemes') ?></a>
<?php } else { ?>
<?php } ?>
So, I have to make it work between this two code snip.
<?php if(in_category( array( 5,10 ) ) { // if the current post is in categories 5 or 10 ?>
<?php if ( !is_user_logged_in() ) { // check whether the user is logged in ?>
<p>You'll need to be a member to view this content.</p>
<?php } else { // user is logged in so go ahead and show content ?>
<?php the_content(); ?>
<?php } ?>
<?php } ?>
Can any one help me?
Thanks,