• Anyone know how to do this?

    This is what I have:

    <div class="gravatar">
    <?php echo get_avatar( get_the_author_id(), $size = '96', $default = '<path_to_url>' ); ?>
    <br />
    <?php the_author_posts_link(); ?>
    </div>

    But that just displays the authors name under the Gravatar, linked to the author’s page.

    I need to do this: <a href="url to author's page"><?php echo get_avatar( get_the_author_id(), $size = '96', $default = '<path_to_url>' ); ?></a>

    Anyone know how?

    I tried: <a href="<?php echo $curauth->user_url; ?>"><?php echo get_avatar( get_the_author_id(), $size = '96', $default = '<path_to_url>' ); ?></a>
    but it didn’t work (and yes, I have the variable $curauth before the loop, and it’s correct and functioning).

    Thanks in advance!

Viewing 15 replies - 1 through 15 (of 17 total)
  • Try <a href="' . get_the_author_meta('url') . "><?php echo get_avatar( get_the_author_id(), $size = '96', $default = '<path_to_url>' ); ?></a>

    Thread Starter geezerd

    (@geezerd)

    Nope.
    Niether did <a href="<?php get_the_author_meta('url') ?>"><?php echo get_avatar( get_the_author_id(), $size = '96', $default = '<path_to_url>' ); ?></a>

    Just goes to http:mysite/. get_the_author_meta(‘url’) .

    How about <?php echo get_the_author_meta('url') ?>?

    Thread Starter geezerd

    (@geezerd)

    Nope

    Oops … my bad, still not working ??

    OK … this just was not going to get the best of me ??

    <a href="<?php echo get_bloginfo('url') . '/archives/author/' . get_the_author_meta('login'); ?>">
    	<?php echo get_avatar( get_the_author_id() ); ?>
    </a>

    I believe this works along what I am understanding you want. I ran it on my test server against three of my themes and it produces the results I expected. You may need to add some style elements to taste.

    (If nothing else I think its something I will add to a future theme.)

    Thread Starter geezerd

    (@geezerd)

    WooHoo!
    Thanks!
    It was a touch off, it’s not ‘/archives/author/’ but just ‘/author/’
    but that was easy to figger out.
    Thanks again!

    @geezerd – The href link is seems to be dependent on the permalink structure of your blog. It just happens I was using the “Numeric” setting on my test server and did not think to actually check the other permalink structures until I read your last post.

    Glad you found the correct link for your blog.

    Where do you post the code?

    Yes, where do you post this code?
    I am having a problem because the author link that is found below a post has a wrong URL. It is showing https://www.mydomain.com/author/admin instead of https://www.mydomain/blog/author/admin.

    Anybody know what page should be edited?

    I use this to show Gravatars and link to post authors in the sidebar:

    In function.php…

    function get_the_avatars_with_link_to_authors(){
    	$authors = get_users_of_blog();
    
    		foreach ($authors as $author){
    			$author_data = get_userdata($author->user_id);
    			$author_nicename = $author_data->user_nicename;
    			$author_displayname = $author_data->display_name;
    
    			$link .= '<li><a href="' . get_author_posts_url($author_data->ID) . '" title="' . sprintf( __( "Ver post de %s" ), $author_displayname ) . '">' . get_avatar($author_data->ID,$size = '64') . '</a></li>';
    		}
    
    	return $link;
    }

    In sidebar.php…

    <ul>
              	<?php printf( __( '%s', 'libra' ), get_the_avatars_with_link_to_authors() ) ?>
              </ul>

    Not the same, but I didn’t find out a solution in WordPress Forums to do what I need.

    Hi guys!

    @ astracan I got this to work perfect but do you know how I can hide the administrator’s avatar/link from showing in the sidebar? I only need to show authors and not the admin.
    Cheers! ??

    Completely untested but what about:

    foreach ($authors as $author){
    	$author_data = get_userdata($author->user_id);
    	$author_nicename = $author_data->user_nicename;
    	$author_displayname = $author_data->display_name;
    	$link .= '<li>';
    	if ( !is_admin() ) $link .= '<a href="' . get_author_posts_url($author_data->ID) . '" title="' . sprintf( __( "Ver post de %s" ), $author_displayname ) . '">';
    	$link .= get_avatar($author_data->ID,$size = '64');
    	if ( !is_admin() ) $link .= '</a></li>';
    }

    Thanks esml – I’ll give that a try and let you know how I get on ??

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘How to make Gravatar image a link to author’s page?’ is closed to new replies.