WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
[resolved] Simple check if more than one author (4 posts)

  1. Joshua David Nelson
    Member
    Posted 2 years ago #

    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/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    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.

  3. Joshua David Nelson
    Member
    Posted 2 years ago #

    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

  4. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 2 years ago #

    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; ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic