0

On a blog, i'm using the following to display the post authors avatars:

<a href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>" style="color:#ffffff;"><?php echo get_avatar( get_the_author_meta( 'ID' )); ?></a>

But some posts have more than one author, and this only displays one avatar, how can I get this to display both authors avatars?

Thanks

0

The obvious answer is to use get_avatar() twice using different author IDs. As you must be aware given your code above (assuming that is your code and not code cribbed from elsewhere), the first parameter of that function accepts an author ID or the associated author email address.

However, you don't explain how you have associated multiple authors to the post so an answer beyond the rather trivial answer just given is not possible. If you can expand the question, I can expand the answer.

  • Thanks for your reply, I have been able to add multiple authors to a post using co-authors plus plugin, but this plugin does not affect how authors meta data is displayed via the page template. How would I use get_avatar() twice using different author IDs without actually putting their ID in the code because it could be different for each post? – Adrian Apr 7 '15 at 17:38
  • Well, that is exactly the question. How you retrieve/use those author IDs depends on how "Co-Authors Plus" stores those IDs, and as I don't use that plugin I don't know. – s_ha_dum Apr 7 '15 at 17:43
  • I actually don't know myself, i've just looked in DB via phpmyadmin and searched for one of the posts that has 2 authors, there is only 1 entry for this post in wp_posts and post_author only has 1 ID in, though in the template I have used coauthors_posts_links() to display the names with links to their profiles and they both appear. – Adrian Apr 7 '15 at 17:55
0

Here we go, found a nice thread which gave some answers and developed this which works a treat:

if ( class_exists( 'coauthors_plus' ) ) {
    $co_authors = get_coauthors();
    foreach ( $co_authors as $key => $co_author ) {
        $co_author_classes = array(
            'co-author-wrap',
            'co-author-number-' . ( $key + 1 ),
        );
        echo '<div class="' . implode( ' ', $co_author_classes ) . '"><a href="' . get_author_posts_url($co_author->ID) . '" style="color:#ffffff;">';
        echo userphoto_thumbnail( $co_author );
        echo '</a></div>';
    }
} 

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.