Show biographies for co-authors at the end of your post

In the WordPress.org forums, doubleedesign says:

I want to add the authors’ biographies to the end of each post.

Awesome… it’s pretty simple to do. Conceptually, what we need to do is load our co-authors, and then loop through printing the relevant information for each one.

You’ll want to put the following code snippet within The Loop in any template you’d like the bios to appear.

[sourcecode language=”php”]
/**
* Show multiple Co-Author biography fields at the bottom of a single post
* This snippet should be placed within The Loop
*/
if ( class_exists( ‘coauthors_plus’ ) ) {
// Get the Co-Authors for the post
$co_authors = get_coauthors();
// For each Co-Author, echo a wrapper div, their name, and their bio if they have one
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 ) . ‘">’;
echo ‘<h4 class="co-author-display-name">’ . $co_author->display_name . ‘</h4>’;
// Only print the description if the description exists
if ( $description = get_the_author_meta( ‘description’, $co_author->ID ) )
echo ‘<p class="co-author-bio">’ . $description . ‘</p>’;
echo ‘</div>’;
}
}
[/sourcecode]

If you’d like other co-author details to appear as well, like their avatar for instance, you can modify the output within the foreach loop.

4 responses

  1. bobbydigital Avatar
    bobbydigital

    Thanks for this, very helpful.

  2. Daniel,

    What’s a simple way to check in php if there is more than one author?

    For example, I’d like to replace my author avatar at the top of a post with just the blog logo in cases were there are multiple authors (using co-authors plus, of course), and I’d like to remove/replace the custom author box at the bottom of a post for these types as well. So I just need a quick if-then statement, but I’m not yet familiar with the plugin, hoping it’s something easy you can give me :). If number of authors is greater than one…

    Thanks!
    Joshua

Leave a Reply

Your email address will not be published. Required fields are marked *