• 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…

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

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

    (@danielbachhuber)

    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.

    Thread Starter Joshua David Nelson

    (@joshuadnelson)

    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 Contributor Daniel Bachhuber

    (@danielbachhuber)

    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.