Support » Plugin: Co-Authors Plus » Detecting number of Authors

  • muzKore

    (@muzoid)


    In the plugin, there is a stock standard function exists check for swapping out the list author link for the plugin variant.
    What I ma wanting to know is if there is a way to query the number of authors.
    eg. If more that one author, use Authors: else if there is only one, use Author:

    As it stands, the function is present when the plugin is active so it will always use the plugin version to display the authors links whether there is one or more.

    What I am wanting to know is how do you say ‘if the function exists and if it shows that there is more than one author for that post’ or if the number of authors is greater than one.

    Any insight would be great.

    Cheers

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter muzKore

    (@muzoid)

    Just a note that I found a work around that does the job for the time being.

    
    $author = coauthors_posts_links( null, null, null, null, false );
    $author_prefix = (strpos( $author_string , ' and ' ) !== false) ? 'Authors' : 'Author' ;
    

    This returns the Authors (instead of outputting to the screen) and puts them into a $author variable. I can then test if there is a string of ‘ and ‘ in the $author variable. If it finds it, then there is more than one author. Obviously it would break if a person has the word ‘and’ in their name.

    As I said, a temporary workaround till I get my question answered.

    Cheers

    Plugin Support Niels Lange

    (@nielslange)

    Hello @muzoid 👋

    Where do you expect to see ‘Author’ instead of ‘Authors’ in case only one author exist? Are you referring to the overview in WP Admin or to the display logic on the frontend?

    I’m asking as I when using the plugin with the Twenty Twenty-One theme, I only see the author names but no author(s) label:


    Link to image: https://d.pr/i/vvb5ka

    // Check if guest authors enabled
    if ( is_guest_authors_enabled() ) {
      
      // Get author(s) of post, assign letter value s if count greater than 1, else empty
      $S = 1 < count( get_coauthors() ) ? 's' : '';
    
      // Set string with label, value of $S, and author name(s) with link
      $authors = "Author{$S} " . coauthors_posts_links( null, null, null, null, false );
    
      // select output type and delete the other
      echo $authors;  <or>  return $authors; 
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.