• I was struggling for a while for posts that have both a regular author and a guest author. This may be of some assistance.

    This piece of code is for displaying the profile image for the guest author. In my build, I have post thumbnails turned on, which allows you to select a profile image for the guest author. I should note, I also installed “Easy Author Image” plugin, which allows me to upload profile pictures for regular users, rather than Gravitars. However, if one is not uploaded it will default to the regular Gravitar for the user. This code will do the same for this. You can set something else for the default Gravitar image (i.e. looking up the real Gravitar based on email, etc) but for my build it wasn’t necessary.

    $img = get_the_post_thumbnail($coauthor->ID, 'thumbnail');
    foreach( get_coauthors() as $coauthor ) :
    if( $coauthor->type == 'guest-author' ){
    	 if ($img != ''){
    	 	echo $img;
    	 } else {
    		 echo '<img src="https://www.gravatar.com/avatar/f7b528317cff8325abe43b33565daf96?size=40" alt=" " />';
    	 }
    	 if( $coauthor->type !== 'guest-author' ){
            echo get_avatar( $post->post_author);
         }
    } else {
         echo get_avatar( $post->post_author);
    }
    endforeach;

    This piece worked unaltered, which just loops through the authors names.

    if ( function_exists( 'coauthors_posts_links' ) ) {
      coauthors_posts_links();
    } else {
       the_author_posts_link();
    }

    https://www.ads-software.com/plugins/co-authors-plus/

  • The topic ‘A little help for other users.’ is closed to new replies.