I saw awhile ago on a support Forum that you can show a authors rank on a post in wordpress but I can't seem to find the post again but instead of words I want it to show an image if anyone could point me in the direction of would be nice
-
1What exactly are you asking? Do you want to echo the user's role? Or an image representing that role? All you need to do is to get the author's role in a variable and then use that variable to show respective image... maybe via an if statement.– Christine Cooper ♦Commented Feb 11, 2015 at 3:19
-
an image representing that role– Brittany QuakeCommented Feb 11, 2015 at 3:46
-
Also, in order to get the required feedback, be clear in your question, and also show your research efforts and code, working or not. This will help others to help you with the correct info that you need. Thank you :-)– Pieter GoosenCommented Feb 11, 2015 at 5:10
-
Ok a few months ago I found a code I believe on here but can't re find it it was displaying a user's rank admin subscriber I want to use that code so that when I post it will show my rank admin but instead of words I want it to show an image I'll keep looking for the code I round this code [code] <?php get_the_author_meta( $field, $userID ); ?> [/code]– Brittany QuakeCommented Feb 11, 2015 at 6:49
-
Something in the order of this– Pieter GoosenCommented Feb 11, 2015 at 7:03
Add a comment
|
1 Answer
There is various approach you could take. All you need to do essentially is to get the author's role and put it in a statement of sort.
For example, let's get the author role first by:
// inside the loop
$author_role = get_the_author_meta('roles', $post->post_author);
Then just use do a if statement like:
if ($author_role == 'contributor') {
echo '<img src="contributor-ranked-user.png" />';
} else if ($author_role == 'author') {
// ...
Or to optimise it a bit, you could just target the filename if you can add the name of the role within it, something like this maybe:
echo '<img src="'. $author_role .'-ranked-user.png" />';