0

I have a blog with multiple authors. Each author has an image inside the "/ wp-content/themes/mytheme/img/authornamecomeshere.png" directory, and each image has the author's name. I would like to put a link from these sites reviewers along with the image, and each image automatically appear under the name.

The code I'm using is this:

<?php _e('Posted by'); ?> 

<a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>" rel="author">

<img src="/wp-content/themes/mytheme/img/authornamecomeshere.png" alt="author" />

<?php the_author_meta('display_name'); ?>

</a>

I'd like to do something like this:

Posted by: 
if author1: <a href="author1site.com"><img src="/wp-content/themes/mytheme/img/author1.png" /></a>

Posted by: 
if author2: <a href="author2sitesite.com"><img src="/wp-content/themes/mytheme/img/author2.png" /></a>

I'd like do this without plugin. Could anyone help me?

1 Answer 1

0

You can use get_the_author_meta to retrieve the username for the author of the current post in the loop. You could then use that in the image URL.

<?php _e('Posted by'); ?> 

<a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>" rel="author">

<img src="/wp-content/themes/mytheme/img/<?php echo esc_attr( get_the_author_meta( 'user_login' ) ); ?>.png" alt="author" />

<?php the_author_meta('display_name'); ?>

</a>

You can also use get_the_author_meta if the image file name is a combination of the author's first and last name, by passing 'first_name' or 'last_name' to the function to retrieve these values.

1
  • Hi! Just a doubt rs The image is a combination of the author's name, the image and name of the author of the post is the same, but the image that is showing is as if there was not a directory. I used the 'first_name'. THX!
    – user52466
    Jun 7, 2014 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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