1

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 } ?>

1 Answer 1

2

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;
1
  • thanks You, that's exactly what I was looking for. You rock!
    – jimilesku
    Jul 28, 2012 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.