It would look something like this to test if a user is a subscriber.
<?php
global $current_user;
get_currentuserinfo();
if ( user_can( $current_user, "subscriber" ) ){
// Show Role
// Show Subscriber Image
}
in your case if you want to do multiple user checks i would use a switch statement like so
global $current_user;
get_currentuserinfo();
switch (true) {
case ( user_can( $current_user, "subscriber") ):
// Show Role
// Show Subscriber Image
break;
case ( user_can( $current_user, "contributor") ):
// Show Role
// Show Contributor Image
break;
case ( user_can( $current_user, "administrator") ):
// Show Role
// Show Administrator Image
break;
}
you can continue the switch statement with more user roles.
EDITED
global $current_user;
get_currentuserinfo();
switch (true) {
case ( user_can( $current_user, "subscriber") ):
echo '<img src="http:www.impho.com/images/001.jpg">';
break;
case ( user_can( $current_user, "contributor") ):
echo '<img src="http:www.impho.com/images/002.jpg">';
break;
case ( user_can( $current_user, "administrator") ):
echo '<img src="http:www.impho.com/images/003.jpg">';
break;
}
EDITED BASED ON USER REQUESTS
Ok this should do it, replace all the code that you have getting user name,avatar, points and image using the following code.
In your functions place this
function userLooping($role, $img)
{
$user_query = new WP_User_Query( array( 'role' => $role ) );
// User Loop
if ( !empty( $user_query->results ) ):
foreach ( $user_query->results as $user ):
echo '<p>'. $user->display_name.'</p>'; // display user name
echo '<p>'.get_avatar($user->ID).'</p>'; // display user avatar
//echo '<p>Points: '.cp_getPoints(bbp_get_reply_author_id()).'</p>';
echo '<p>'.$img.'</p>'; //display image based on role
endforeach;
endif;
}
remove the //
in front of echo
above
Place the following inside your template
<?php
$args = array( array('role' => 'administrator', 'img' => '<img src="http://placeape.com/100/100">'),array('role' => 'subscriber', 'img' => '<img src="http://placekitten.com/100/100">'));
foreach ($args as $arg):
userLooping($arg['role'],$arg['img']);
endforeach;
?>
to add more roles and images, just add a new array after subscriber