Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    I was just wondering:

    I was trying to do the same thing as you, and to get multiple authors to show up at the same time.

    I must confess, I got a little confused as to what to do with this.

    `public function get_author_to_show($single){
    if ($this->params[‘author’] == ‘yes’):
    $lcp_userdata = get_userdata($single->post_author);
    $author_name = $lcp_userdata->display_name;
    if($this->utils->lcp_not_empty(‘author_posts_link’) &&
    $this->params[‘author_posts_link’] == ‘yes’){
    $link = get_author_posts_url($lcp_userdata->ID);
    return “<a href=” . $link . ” title='” . $author_name .
    “‘>” . $author_name . “</a>”;
    } else {
    return $author_name;
    }
    else:
    return null;
    endif;
    }`

    How do you modify this to show the multiple authors?

    I have only managed to break this in several ways.

    Thank you so much,
    Alexa

    Thread Starter [email protected]

    (@hobo343gmailcom)

    Hi
    No i’m still looking for a solution to this.

    Hello, I am not sure if you are still looking for a solution. Here is what I came up with, whether or not it’s proper, I’m not sure.

    Original:

    public function get_author_to_show($single){
        if ($this->params['author'] == 'yes'):
          $lcp_userdata = get_userdata($single->post_author);
        $author_name =  $lcp_userdata->display_name;
        if($this->utils->lcp_not_empty('author_posts_link') &&
        $this->params['author_posts_link'] == 'yes'){
          $link = get_author_posts_url($lcp_userdata->ID);
          return "<a href=" . $link . " title='" . $author_name .
            "'>" . $author_name . "</a>";
        } else {
          return $author_name;
        }
        else:
          return null;
        endif;
      }

    My edit:

    public function get_author_to_show($single){
        if ($this->params['author'] == 'yes'):
          $lcp_userdata = get_userdata($single->post_author);
        $author_name =  $lcp_userdata->display_name;
        if($this->utils->lcp_not_empty('author_posts_link') &&
        $this->params['author_posts_link'] == 'yes'){
    		if ( function_exists( 'coauthors_posts_links' ) ) {
            			$coauthors =' '.coauthors_posts_links();
    					return $coauthors;
    					} else {
          $link = get_author_posts_url($lcp_userdata->ID);
          return "<a href=" . $link . " title='" . $author_name ."'>" . $author_name . "</a>";
    					}
        } else {
    		if ( function_exists( 'coauthors' ) ) {
            			$coauthors =' '.coauthors();
    					return $coauthors;
    					} else {
          return $author_name;
    					}
        }
        else:
          return null;
        endif;
      }

    Quick edit, in my code, replace

    coauthors_posts_links();

    with

    coauthors_posts_links(null, null, null, null, false);

    The former echoes the links, so my code would both echo and return the text. The latter stops the echo and only returns.

    Do the same with

    coauthors(null, null, null, null, false);

    Whoop, now that I’m looking at it, my solution didn’t work. It was showing the coauthors from another loop… Whomp whomp. =(

    Tried a different solution. Kind of a roundabout way to do this…. but it seems to be working for the moment….

    public function get_author_to_show($single){
        if ($this->params['author'] == 'yes'):
          $lcp_userdata = get_userdata($single->post_author);
        $author_name =  $lcp_userdata->display_name;
    
    	if ( function_exists( 'coauthors' ) ) {
    
    					global $coauthors_plus;
    					$my_coauthor_links_array = array();
    					$my_coauthor_array = array();
    					$my_coauthor_terms = get_the_terms($single -> ID,$coauthors_plus->coauthor_taxonomy);
    					foreach( $my_coauthor_terms as $my_coauthor ) {
    
    				$my_coauthor_slug = preg_replace( '#^cap\-#', '', $my_coauthor->slug );
    				$my_post_author = get_user_by( 'slug', $my_coauthor_slug );
    				$my_coauthor_name = $my_post_author->first_name . ' ' . $my_post_author->last_name;
    				$my_coauthor_link = get_author_posts_url($my_post_author->ID);
    				$my_coauthor_name_link = "<a href=" . $my_coauthor_link . " title='" . $my_coauthor_name ."'>" . $my_coauthor_name . "</a>";
    				array_push($my_coauthor_links_array, $my_coauthor_name_link);
    				array_push($my_coauthor_array, $my_coauthor_name);
    					}
    
    					$my_coauthor_links_comma_list= implode(', ',$my_coauthor_links_array);
    					$my_last_coauthor_link = array_pop($my_coauthor_links_array);
    					$my_coauthor_links_output= implode(', ',$my_coauthor_links_array);
    					if($my_coauthor_links_output){
    					$my_coauthor_links_output .= ' and ';
    					}
    					$my_coauthor_links_output .= $my_last_coauthor_link;
    
    					$my_coauthor_comma_list= implode(', ',$my_coauthor_array);
    					$my_last_coauthor = array_pop($my_coauthor_array);
    					$my_coauthor_output= implode(', ',$my_coauthor_array);
    					if($my_coauthor_output){
    					$my_coauthor_output .= ' and ';
    					}
    					$my_coauthor_output .= $my_last_coauthor;
    
    					} 
    
        if($this->utils->lcp_not_empty('author_posts_link') &&
        $this->params['author_posts_link'] == 'yes'){
    		if ( function_exists( 'coauthors' ) ) {
    
    					return $my_coauthor_links_output;
    
    					} else {
          $link = get_author_posts_url($lcp_userdata->ID);
          return "<a href=" . $link . " title='" . $author_name ."'>" . $author_name . "</a>";
    					}
        } else {
    		if ( function_exists( 'coauthors' ) ) {
            			return $my_coauthor_output;
    					} else {
          return $author_name;
    					}
        }
        else:
          return null;
        endif;
      }

    I swapped out
    if ( function_exists( 'coauthors' ) )

    for

    if ( get_the_terms($single -> ID,'author') )

    because it was throwing an error for posts that do not have any coauthors.

    Thread Starter [email protected]

    (@hobo343gmailcom)

    Thank you for doing ALL of the work on this — i will test soon.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘lcp and coauthors plus’ is closed to new replies.