• Resolved noelgreen

    (@noelgreen)


    I want to display something different at the bottom of a post depending on what role the post’s author was/is.

    For example… and this doesn’t work… but…

    <?php
    if (the_author_meta('user_level') == 'Editor'): ?>
    <p>Boogie Time</p>
    <?php else: ?>
    <p>Time to Boogie</p>
    <?php endif; ?>

    Anyone know how to do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter noelgreen

    (@noelgreen)

    Got it!

    Step 1) Download the User Role Editor plugin here.

    Step 2) Set a user role with a specific level (i.e., “level 5”)

    Step 3) Add the following code where you want to display the conditional text.

    <?php $authorrole = esc_attr(get_the_author_meta('user_level') );
    	if ($authorrole == 5) { ?>
    		<p>This displays if the user is in the group set to "level 5"</p>
    	<?php } else {?>
    		<p>If the user is in any group other than the one set to "level 5" this displays.</p>
    <?php } ?>

    Simply change the # to the level you want to use as the level. Alternatively you should be able to change the function so that if a user is greater than a certain level it will display (though I’ve not tested this)… like so…

    <?php $authorrole = esc_attr(get_the_author_meta('user_level') );
    	if ($authorrole > 2) { ?>
    		<p>This displays if the user is in the group set higher than "level 2"</p>
    	<?php } else {?>
    		<p>If the user is in any group other than the one set lower than "level 2" this displays.</p>
    <?php } ?>

    Hope this helps others!

    Thread Starter noelgreen

    (@noelgreen)

    Or, let’s say you want to get the information for the current user and display something if they’re at or above a level.

    That would be done like this…

    <?php
    global $current_user;
    get_currentuserinfo();
    	$authorrole = esc_attr($current_user->user_level );
    	if ($authorrole == 5) { ?>
    
    Do something.
    
    	<?php } else {?>
    
    Do something else.
    
    <?php } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional Display Based on Role’ is closed to new replies.