Get WordPress author link by ID

TheOne picture TheOne · Jun 3, 2013 · Viewed 10.1k times · Source

I'm trying to link a to 3 different authors by author ID to their author page.

  1. (author/adrian-cole/)
  2. (author/steve-helme/)
  3. (author/scott-oneill/)

How would I go about doing this?

Example:

<div>Adrian Cole <a href="<?php get_author_posts_url(get_the_author_meta('ID')==1) ?>">Read more</a></div>
<div>Steve Helme <a href="<?php get_author_posts_url(get_the_author_meta('ID')==2) ?>">Read more</a></div>
<div>Scott O'Neill <a href="<?php get_author_posts_url(get_the_author_meta('ID')==3) ?>">Read more</a></div>

This will be in the sidebar.php file as "profile widgets" so the author ID can't be grabbed from the author who published the post

Im guessing this wont be in the loop? am wrong? Im new to wordpress ha!

Answer

Jake picture Jake · Jun 3, 2013

the wordpress functoin get_author_posts_url($id) returns the url you need.

Something like this should work:

<?php $author_id1 = 1; $author_id2 = 2; $author_id3 = 3; ?>

<div><?php the_author_meta( 'display_name', $author_id1 ); ?> <a href="<?php echo get_author_posts_url($author_id1); ?>">Read more</a></div>
<div><?php the_author_meta( 'display_name', $author_id2 ); ?> <a href="<?php echo get_author_posts_url($author_id2); ?>">Read more</a></div>
<div><?php the_author_meta( 'display_name', $author_id3 ); ?> <a href="<?php echo get_author_posts_url($author_id3); ?>">Read more</a></div>

where 1, 2, and 3 are the author ids of your authors.

EDIT: You are right in assuming this falls outside "the Loop". If you don't know the IDs of the authors, you can get them in this way: http://wordpress.org/support/topic/getting-user-id-from-username