Multiple Authors for a Post

multiple-authors

If you have a magazine-like website, you might need to specify multiple authors for a single post. There’s a great plugin called Co-Authors Plus that will let you do this.

Once installed, you can use many template tags (see here), or you can use the CoAuthorsIterator Class to your specific needs, which is what I’m going to do.

The Post Info area of Genesis can be customized using a filter, but for it to work we’ll need a function that returns a result instead of echos it (the provided template tags echo the result). Even better, we could create a shortcode to be used in the post info section.

To set up the shortcode, add the following to your functions.php file:

That will create a shortcode that displays all the authors, with a link to their author archive page.

Finally, you’ll need to add your shortcode to a post info filter. See this post for more information on what you can put in your post info filter. My filter will simply show the authors followed by the date

Bill Erickson is a WordPress Consultant who builds custom websites using WordPress as a CMS and the Genesis framework. He contributes to the WordPress community through free themes, plugins, tutorials, and core patches. He's also a cofounder of the BIL Conference (the open analog to the TED Conference).

Looking for more great tutorials? See them all!

Comments

  1. Joshua says:

    Bill,

    How would I do this for my Thesis theme with this plugin? Is it pretty similar? I’m hoping to have the multiple authors show up in the fashion of “Author 1, Author 2 and Author 3″ or “Author 1 and Author 2″ but I’ll settle for “Author 1, Author 2, Author 3″. I just want to make sure I can have all applicable authors show up in the headline.

    Thanks,
    Joshua

    • Bill Erickson says:

      Instead of using a filter on genesis_post_info, you could write a function and hook it into thesis_hook_byline_item. Be sure to remove the Author from the byline in Thesis Options first.

      For example (untested code):

      add_action('thesis_hook_byline_item', 'multi_authors');
      function multi_authors() {
      $i = new CoAuthorsIterator();
      $return = '';
      $i->iterate();
      $return .= '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'">'.get_the_author_meta('display_name').'</a>';
      while($i->iterate()){
      $return.= $i->is_last() ? ' and ' : ', ';
      $return .= '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'">'.get_the_author_meta('display_name').'</a>';
      }
      echo $return;
      }
  2. Al says:

    Hi Bill,
    thank you for this appreciated tutorial.
    I would display, with coauthor plus plugin, also the list of (both) authors and co-authors in a sidebar, but all my attemps haven’t success. Could you kindly tell me where is the bug?

    I’ve insert in functions.php of my theme


    function get_coauthor_list() {
    global $wpdb;
    $authors = implode("','",get_terms('author',array('fields'=>'names')));
    $sql = "SELECT ID " .
    "FROM {$wpdb->users} " .
    "WHERE user_login IN ('{$authors}') " .
    "ORDER BY display_name";
    return $wpdb->get_col($sql);
    }

    and in the sidebar.php file

    <div class="author" id="author-">

    <a href="">

    but the result is a display of some co-authors and not other authors!

    Do you know a different solution for achieve the target of a complete author/coauthor list?

    Thank you,
    Al

Trackbacks

  1. [...] Erickson wrote up how to attribute multiple authors to a single [...]

  2. [...] Erickson wrote up how to attribute multiple authors to a single [...]

  3. [...] Erickson wrote up how to attribute multiple authors to a single [...]

Speak Your Mind

*

If you'd like to include code in your post, please post it to http://gist.github.com and include a link.