Forums

How to make Gravatar image a link to author's page? (18 posts)

  1. geezerd
    Member
    Posted 2 years ago #

    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!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  3. geezerd
    Member
    Posted 2 years ago #

    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') .

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  5. geezerd
    Member
    Posted 2 years ago #

    Nope

  6. Edward Caissie
    Member
    Posted 2 years ago #

    Oops ... my bad, still not working :(

  7. Edward Caissie
    Member
    Posted 2 years ago #

    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.)

  8. geezerd
    Member
    Posted 2 years ago #

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

  9. Edward Caissie
    Member
    Posted 2 years ago #

    @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.

  10. halfday
    Member
    Posted 2 years ago #

    Where do you post the code?

  11. newtech
    Member
    Posted 2 years ago #

    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 http://www.mydomain.com/author/admin instead of http://www.mydomain/blog/author/admin.

  12. newtech
    Member
    Posted 2 years ago #

    Anybody know what page should be edited?

  13. astracan
    Member
    Posted 2 years ago #

    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.

  14. vanoccupanther1
    Member
    Posted 1 year ago #

    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! :)

  15. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    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>';
    }
  16. vanoccupanther1
    Member
    Posted 1 year ago #

    Thanks esml - I'll give that a try and let you know how I get on ;)

  17. vanoccupanther1
    Member
    Posted 1 year ago #

    Well, I gave it a whirl and I couldn't get it to work. Here's my code:
    In functions.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 style="list-style-type:none;list-style-position: outside"><a style="text-decoration:none;" href="' . get_author_posts_url($author_data->ID) . '" title="' . sprintf( __( "View %s's profile" ), $author_displayname ) . '">' . get_avatar($author_data->ID,$size = '35') . $author_displayname . '</a></li>';
    		}
    	return $link;
    }

    and in my sidebar I have:

    <?php printf( __( '%s', 'libra' ), get_the_avatars_with_link_to_authors() ) ?>
  18. waterjeorme
    Member
    Posted 1 year ago #

    The solution from cais is great however: get_the_author_id() is deprecated as of 2.8.

    For WordPress 2.8, please use get_the_author_meta('user_email').

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.