• If your site runs Coauthors Plus to manage posts with multiple authors, you’ll notice that WPP does not know that and will output just the first author of a post with multiple authors.

    I added this code to version 2.3.2 in wordpress_popular_posts.php starting on line 1070.

    The original code here is:

    if ( $instance['stats_tag']['author'] ) {
    	$display_name = get_the_author_meta('display_name', $p->uid);
    	$stats .= ($stats == "") ? "<span class=\"wpp-author\">" . __('by', 'wordpress-popular-posts')." {$display_name}</span>" : " | <span class=\"wpp-author\">" . __('by', 'wordpress-popular-posts') ." {$display_name}</span>";
    }

    The hack to include your Coauthors Plus authors:

    /* hack to add co-authors */
    
    if ( $instance['stats_tag']['author'] ) {
    
    	$count = 1;
    
    	if ( function_exists( 'get_coauthors' ) ) {
    		$co_authors = get_coauthors($p->id);
    		$total_authors = count($co_authors);
    		$author_names = '';
    		foreach ( $co_authors as $key => $co_author ) {
    			if ($count <= 1) { $author_names .= $co_author->display_name;}
    			else if ($count == $total_authors && $total_authors > 2) { $author_names .= ', and ' . $co_author->display_name; }
    			else if ($count == $total_authors && $total_authors = 2) { $author_names .= ' and ' . $co_author->display_name; }
    			else { $author_names .= ', ' . $co_author->display_name; }
    			$count++;
    		}
    		$display_name = $author_names;
    	} else {
    		$display_name = get_the_author_meta('display_name', $p->uid);
    	}
    	/* $display_name = get_the_author_meta('display_name', $p->uid); */
    	$stats .= ($stats == "") ? "<span class=\"wpp-author\">" . __('by', 'wordpress-popular-posts')." {$display_name}</span>" : " | <span class=\"wpp-author\">" . __('by', 'wordpress-popular-posts') ." {$display_name}</span>";
    }

    This code checks for the presence of Coauthors Plus, and will fail gracefully to the original code if not present, which would make it suitable for inclusion in a future release if the maintainer so wishes. It will also manage the proper punctuation of the list of names, no matter how many authors are on a post.

    Thanks,
    Brady

    https://www.ads-software.com/extend/plugins/wordpresscom-popular-posts/

    https://www.ads-software.com/extend/plugins/wordpress-popular-posts/

  • The topic ‘Coauthors Plus and WordPress Popular Posts’ is closed to new replies.