Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function lxb_rssm_coauthors( $post_id, $link_to = 'user_url', $label = 'display_name', $last_sep = "and " ) {
- $post_id = absint( $post_id );
- // If coauthors does not exist, bail with single author link.
- if( ! class_exists( 'CoAuthorsIterator' ) ) {
- $userdata = get_userdata( get_the_author_meta( 'ID' ) );
- $user_label = lxb_rssm_user_label( $userdata, $label );
- if( ! empty( $link_to ) ) {
- $link = lxb_rssm_user_link( $userdata, $link_to );
- return "<a href='$link'>$user_label</a>";
- }
- return $display_name;
- }
- // If coauthors does exist, instantiate it.
- $co = new CoAuthorsIterator( $post_id );
- // Start the output.
- $coauthors = '';
- // If we can iterate through the multi authors...
- if( method_exists( $co, 'iterate' ) ) {
- // Through each author...
- while( $co -> iterate() ) {
- // Put a comma between each, or an amp before the final one.
- $coauthors .= $co -> is_last() ? __( "$last_sep" ) : ',';
- $userdata = get_userdata( get_the_author_meta( 'ID' ) );
- $user_label = lxb_rssm_user_label( $userdata, $label );
- if( ! empty( $link_to ) ) {
- $link = lxb_rssm_user_link( $userdata, $link_to );
- // The display name wrapped in the user_url.
- $coauthors .= "<a href='$link'>$user_label</a> ";
- } else {
- $coauthors .= "$user_label ";
- }
- }
- // Tidy up the output
- $coauthors = ltrim( $coauthors, ', ' );
- $coauthors = ltrim( $coauthors, 'and ' );
- return $coauthors;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement