How To Display Coauthors In The Contents List

Are you using the  CoAuthors Plugin and want to list coauthors in your issue contents page? The issuem_author_name filter is here to save your day.

The  issuem_articles shortcode is responsible for creating the contents list on an issue page. By default it will list the assigned WordPress user which, if you are using the CoAuthors Plus plugin, is not really what you want. You want all the coauthors listed, preferably each one linked to their respective archive.

Fortunately, IssueM provides an easy way to override the byline.

Before the  issuem_articles shortcode outputs the byline it applies a filter, issuem_author_name. We can replace the byline with whatever we want by simply hooking a custom function to that filter. Add this code to your theme’s functions.php file:

function override_byline($orig_author, $post_ID) { $authors = ''; /* get the coauthors */ $coauthors = get_coauthors( $post_ID ); /* if no coauthors then just user the original author */ if ( count($coauthors) == 0 ) { $authors = $orig_author; } else { /* loop through coauthors and build the byline */ foreach( $coauthors as $coauthor ) { $authors .= ((strlen($authors) > 0) ? '&nbsp;,&nbsp;' : '') . '<a href="' . get_author_posts_url( $coauthor->ID ) . '" title="View all posts by ' . $coauthor->display_name . '">' . $coauthor->display_name . '</a>'; } } return $authors; } add_filter( 'issuem_author_name', 'override_byline', 999, 2 );

The function is passed the original byline, along with the ID of the post. It then uses a CoAuthors Plus function, get_coauthors, to get a list of the authors and builds the replacement byline. If no coauthors are found then the original byline is retained.

If you are not familiar with filters and their close relatives, actions, then it’s well worth reading up on these powerful tools for customising your WordPress site.

Still need help? Contact Us Contact Us