• I was wondering how to modify the mobile tabs on a website I have. I want to only show one specific tab if a freelancer logs in on mobile and a specific tab if an employer logs in. Here is the current code in the page-home.php, archive-project.php and archive-fre_profile.php:

    <section class=”section-wrapper section-profile section-archive-profile”>
    <div class=”list-link-tabs-page”>
    <div class=”container”>
    <a href="”<?php">” class=”active”><?php _e(“Projects”, ET_DOMAIN); ?></a>
    <a href="”<?php">” class=”active”><?php _e(“Profiles”, ET_DOMAIN); ?></a>
    </div>
    </div>

    I want to say if user is freelancer then display projects else if user is employer display profiles. So something like this I thought would work but it doesnt:

    <section class=”section-wrapper section-project section-archive-project”>
    <div class=”list-link-tabs-page”>
    <div class=”container”>
    <?php if( ae_user_role($user_ID) == FREELANCER) {?>
    <a href="”<?php">” class=”active”><?php _e(“Projects”, ET_DOMAIN); ?></a>
    <?php } else if( ae_user_role($user_ID) == EMPLOYER) { ?>
    <a href="”<?php">” class=”active”><?php _e(“Profiles”, ET_DOMAIN); ?></a>
    <?php } ?>
    </div>
    </div>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Are freelancers and employers both subscriber users? How about trying a plugin like Members and creating different user roles, one for freelancers and one for employers? Then you can target each separately. If your tab is in Menus, use a plugin like Menu Item Visibility Control to target roles.

    Thread Starter Beebe

    (@beebe)

    The tabs are not in menus. Take a look – https://www.castmequick.com you have to view it on a mobile device to see what I am talking about.

    It is the tabs that say Castings and Actors.

    Freelancers should view Castings only
    Employers should view Actors only

    Freelancers and Employers are their own role.

    Thread Starter Beebe

    (@beebe)

    I almost have this working:
    <?php
    global $user_login, $current_user;

    if (is_user_logged_in()) {
    get_currentuserinfo();
    $user_info = get_userdata($current_user->ID);
    if (in_array(‘freelancer’, $user_info->roles)) {
    ?>
    ” class=”active”><?php _e(“Projects”, ET_DOMAIN); ?>
    <?php
    }
    }
    ?>

    <?php
    global $user_login, $current_user;

    if (is_user_logged_in()) {
    get_currentuserinfo();
    $user_info = get_userdata($current_user->ID);
    if (in_array(’employer’, $user_info->roles)) {
    ?>
    ” class=”active”><?php _e(“Profiles”, ET_DOMAIN); ?>
    <?php
    }
    }
    ?>

    It switches the tabs but does not switch the content.

    Any suggestions is appreciated.

    The plugin Nav Menu Roles does what you are trying to do. It shows tabs based on the user role.

    You can use Peter’s Login Redirect to send users to different pages based on their role.

    There are bugs in this, but I would code it like that on a “basic and general way”:

    <?php
    global $user_login, $current_user;
    
    if (is_user_logged_in()) {
    get_currentuserinfo();
    $user_info = get_userdata($current_user->ID);
    if (in_array('freelancer', $user_info->roles)) 
    
    {
    
    ?>
    " class="active"><?php _e("Projects", ET_DOMAIN); ?>
    
    <?php
    
        echo '<ul class="freelancer-projects">';
        while ((is_user_logged_in()) AND ('category_name' == 'freelancer-projects')) 
    
              <li>             
    
              <h2 class="title-post"><?php the_title(); ?></h2>
    
              the_excerpt();
    
              the_content();               
    
              </li>                                 
    
        endwhile;
        echo '</ul>';
    
    ?>

    Please note, you might need to use Jquery to dynamically show/hide results loaded from PHP/Mysql and not displayed yet (just tweak ul class=”freelancer-projects” to ul class=”freelancer-projects” id=”toggle”).

    Then from Jquery, it’s very easy to toggle on/off every part of list because you will be able to call it directly in a .js file (content with ids are callable directly on a button or clicky).

    It’s to me the best solution to show or hide data records if a button (a menu tab in your case, is clicked).

    Hope it helps,

    Thread Starter Beebe

    (@beebe)

    I am still a newbie but the below code is almost there. The tabs will change based on which user logs in – which is what I want, but the info displayed below the tab is not correct. The info in the tab seems to always be the first thing listed in the code. So right now, when a freelancer logs in everything is good. But when an employer logs in, it shows the right tab but under the tab it shows “Projects” and not the “Profiles”.

    <?php
    global $user_login, $current_user; 
    
    if (is_user_logged_in()) {
        get_currentuserinfo();
        $user_info = get_userdata($current_user->ID);
        if (in_array('freelancer', $user_info->roles)) {
    ?>
    <a>" class="active"><?php _e("Projects", ET_DOMAIN); ?></a>
    <?php
        }
    }
    ?>  
    
    <?php
    global $user_login, $current_user; 
    
    if (is_user_logged_in()) {
        get_currentuserinfo();
        $user_info = get_userdata($current_user->ID);
        if (in_array('employer', $user_info->roles)) {
    ?>
    <a>" class="active"><?php _e("Profiles", ET_DOMAIN); ?></a>
    <?php
        }
    }
    ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code has now been damaged by the forum’s parser.]

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show Content Different Users after login’ is closed to new replies.