Show different badge based upon the user role

Problem

I have authors page and I need to display a different badge for Authors and Subscribers. Authors on the site have certain abilities that differ from Subscribers and I would like to display a different badge based upon their role.

Example

So when somebody comes to the site either admin author, visitor subscriber… they see the badge on the authors page they are visiting based upon their role. If they are looking at the user who’s role is ‘Author’ than the badge is green, and if the users role is ‘Subscriber’ then the badge is red. Is it possible and how do I make it?

This code doesn’t do the trick 🙁

I was trying to go with this logic but it shows the badge based upon who is looking the authors age not of the author who owns the page. Please help 🙂

 <?php if( is_author_of_current_page() &&  current_user_can('Author') ) { ?>

  green badge

 <?php } elseif( is_author_of_current_page() &&  current_user_can('Subscriber') ) { ?>

  red badge

 <?php } ?>

Solutions Collecting From Web of "Show different badge based upon the user role"

You can use get_queried_object to get data in the current author page:

<?php

$author = get_queried_object();

// uncomment next line to see all author data
// print_r( $author );

if( in_array( 'author', $author->roles ) ) :

    echo "author";

elseif( in_array( 'subscriber', $author->roles ) ) :

    echo "subscriber";

endif;