Forums

User level categories (10 posts)

  1. CreativeWP
    Member
    Posted 10 months ago #

    Hello, I am using this ClasiPress to create a different type of listing classifieds.

    I will select manually who can subscribe or not (only a type of leaders for a religious institution).

    I have 4 categories. 2 of them need to be available to every one at all times (to browse). The 4 will be available to the leaders. The leaders will be able to post in all 4 Categories, and they will be able to view / post all 4 Categories. BUT the main public will only see two. How could I go about it?

    Thanks,

  2. CreativeWP
    Member
    Posted 10 months ago #

    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?

  3. CreativeWP
    Member
    Posted 10 months ago #

    I should use something like this I do imagine:

    <?php if ( is_user_logged_in() ) { ... } ?>

  4. equalmark
    Member
    Posted 10 months ago #

    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 } ?>
  5. CreativeWP
    Member
    Posted 10 months ago #

    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 } ?>
  6. CreativeWP
    Member
    Posted 10 months ago #

    Ah, the categories are 10 and 5

  7. equalmark
    Member
    Posted 10 months ago #

    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 } ?>
  8. CreativeWP
    Member
    Posted 10 months ago #

    My theme does not have Category.php.... hmm.

    Thanks,

  9. equalmark
    Member
    Posted 10 months ago #

    If it has an archive.php then do it in there, if not then index.php.

  10. CreativeWP
    Member
    Posted 10 months ago #

    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,

Reply

You must log in to post.

About this Topic