Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm making use of this custom code to my loop.php file to restrict non-registered members access to posts from a certain category (cat 1)

<?php if (is_user_logged_in() && $cat == '1') { ?> 
<?php the_content(); ?> 
<?php } else { ?> 
<?php the_excerpt(); ?>
<?php } ?> 

However this piece of code doesn't help much as it restricts all posts from other categories as well.

Any suggestions?

share|improve this question
add comment

1 Answer

try this:

<?php 
    //first check if its the category in question
    if ($cat == '1') { 
        //then if the user is logged in show the content
        if (is_user_logged_in()){
            the_content();
        }else{ //if not show the excerpt
            the_excerpt();
        }
    }else{ // and if its not the category show the content
        the_content();
    }
?> 

Update

Judging by your comments you are some defining $cat before the check so add:

$cat = get_query_var('cat');

before the conditional code.

share|improve this answer
    
BRILLIANT!! Thanks a ton, I was trying to use elseifs and so on. Thanks!! –  Sledge81 Jun 26 '11 at 13:35
    
glad y could help. –  Bainternet Jun 26 '11 at 13:37
    
Opps, sorry. Was kinda quick to jump the gun. With the above code even posts in cat 1 are being displayed openly. –  Sledge81 Jun 26 '11 at 13:48
    
Looking at this code, I think in the last instance of else, probably an if statement should come in as well? if its not the category and ignore user status, then show content ?? –  Sledge81 Jun 26 '11 at 14:12
1  
$cat in not automatically defined if its set in the url you need to define it yourself, i updated my answer. –  Bainternet Jun 26 '11 at 14:44
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.