WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
Coauthors Plus and WordPress Popular Posts (1 post)

  1. bswen
    Member
    Posted 1 year ago #

    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

    http://wordpress.org/extend/plugins/wordpresscom-popular-posts/

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by bswen
  • This topic is not a support question
  • WordPress version: 3.5.1