Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. function lxb_rssm_coauthors( $post_id, $link_to = 'user_url', $label = 'display_name', $last_sep = "and " ) {
  2.  
  3. $post_id = absint( $post_id );
  4.  
  5. // If coauthors does not exist, bail with single author link.
  6. if( ! class_exists( 'CoAuthorsIterator' ) ) {
  7.  
  8. $userdata = get_userdata( get_the_author_meta( 'ID' ) );
  9.  
  10. $user_label = lxb_rssm_user_label( $userdata, $label );
  11.  
  12. if( ! empty( $link_to ) ) {
  13.  
  14. $link = lxb_rssm_user_link( $userdata, $link_to );
  15.  
  16. return "<a href='$link'>$user_label</a>";
  17.  
  18. }
  19.  
  20. return $display_name;
  21.  
  22. }
  23.  
  24. // If coauthors does exist, instantiate it.
  25. $co = new CoAuthorsIterator( $post_id );
  26.  
  27. // Start the output.
  28. $coauthors = '';
  29.  
  30. // If we can iterate through the multi authors...
  31. if( method_exists( $co, 'iterate' ) ) {
  32.  
  33. // Through each author...
  34. while( $co -> iterate() ) {
  35.  
  36. // Put a comma between each, or an amp before the final one.
  37.  
  38. $coauthors .= $co -> is_last() ? __( "$last_sep" ) : ',';
  39.  
  40. $userdata = get_userdata( get_the_author_meta( 'ID' ) );
  41.  
  42. $user_label = lxb_rssm_user_label( $userdata, $label );
  43.  
  44. if( ! empty( $link_to ) ) {
  45.  
  46. $link = lxb_rssm_user_link( $userdata, $link_to );
  47.  
  48. // The display name wrapped in the user_url.
  49. $coauthors .= "<a href='$link'>$user_label</a> ";
  50.  
  51. } else {
  52.  
  53. $coauthors .= "$user_label ";
  54.  
  55. }
  56.  
  57. }
  58.  
  59. // Tidy up the output
  60. $coauthors = ltrim( $coauthors, ', ' );
  61. $coauthors = ltrim( $coauthors, 'and ' );
  62.  
  63. return $coauthors;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement