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.

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:

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?

share|improve this question
3  
Please follow up on your other questions. You're already in a position where most people will stay away from answering further ones. –  kaiser Jun 28 '12 at 15:37
    
Any progress on this question? –  kaiser Apr 1 '13 at 19:18
add comment

2 Answers 2

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!' />";
share|improve this answer
    
Hi, thanks for the reply, but would this not display for the logged in user and not the author of the profile? –  david Jun 28 '12 at 15:21
    
@david Yes, you were right. Code fixed. –  kaiser Oct 17 '12 at 15:10
add comment

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?

share|improve this answer
    
thanks for the reply but don't seem to get anything with that, using: if(current_user_can('editor')){ echo 'hello world '; } –  david Jun 27 '12 at 10:11
    
Are you logged in with that role? If you're logged in as administrator, try replacing editor with administrator. Do you want the code to run for logged in users only or any user with the editor role? –  Rutwick Gangurde Jun 27 '12 at 10:14
    
also wouldn't current_user_can only work if you were logged in as an editor, I want to display someone an editor to people visiting the site –  david Jun 27 '12 at 10:14
    
Okay... then you may have to get the users list first, then check their role which is in the users object and do the stuff. –  Rutwick Gangurde Jun 27 '12 at 10:18
add comment

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.