Support » Plugin: Co-Authors Plus » [Plugin: Co-Authors Plus] Simple check if more than one author

  • Resolved Joshua David Nelson

    (@joshuadnelson)


    What’s a simple way to check in php if there is more than one author?

    For example, I’d like to replace my author avatar at the top of a post with just the blog logo in cases were there are multiple authors (using co-authors plus, of course), and I’d like to remove/replace the custom author box at the bottom of a post for these types as well. So I just need a quick if-then statement, but I’m not yet familiar with the plugin, hoping it’s something easy you can give me . If number of authors is greater than one…

    http://wordpress.org/extend/plugins/co-authors-plus/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    You’ll want to do something like this:

    <?php if ( 1 == count( get_coauthors( get_the_id() ) ) ): ?>
    
    // Do whatever with just one coauthor
    
    <?php else: ?>
    
    // Do whatever with more than one
    
    <?php endif; ?>

    The count() function counts how many user objects exist in the array of coauthors.

    Dan,

    Great, thanks. What happens with this code if the co-authors plug-in is deactivated, though? I’m assuming I’d want to find a way to run a function_exists conditional in there as well, right?

    Thanks for your help!
    Joshua

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Yep, good point. You could change it around to something like this instead:

    <?php if ( function_exists( 'get_coauthors' ) && count( get_coauthors( get_the_id() ) ) > 1 ): ?>
    
    // Do whatever with more than one co-author
    
    <?php else: ?>
    
    // Do whatever with just one or when Co-Authors Plus is deactivated
    
    <?php endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Co-Authors Plus] Simple check if more than one author’ is closed to new replies.