if user has a certain role then display image

so close to figuring this out, or not I’m not to sure! Basically what I want to do is on the authors page (so outside the loop) if a user role is an editor I want to display a little badge (but just outputting their name and role at the mo) in their profile. I have:

functions.php:

Read More
function get_user_role($id)
{
    $user = new WP_User($id);
    return array_shift($user->roles);
}

and

author.php:

<?php
global $post;
$aid = $post->post_author;
if ($userlevel == '2') {
echo get_the_author_meta('user_nicename', $aid).' | '.get_user_role($aid);
}

?>

But doesn’t seem to work, any ideas?

Related posts

Leave a Reply

2 comments

  1. In your template:

    // rolename could for e.g. be 'editor' or 'author' or 'administrator'
    author_can( get_the_ID(), 'rolename' ) AND print "<img src='...' alt='A kool badge!' />";
    
  2. Edit: Get all the editors first and then loop over them.

    $users = get_users(array('role' => 'editor'));
    //foreach user,
    //your badge code
    

    Does this help?