How to display avatars in Leader board

front page Forums How-to Questions How to display avatars in Leader board

This topic contains 8 replies, has 3 voices, and was last updated by Avatar WPExperts 4 years, 9 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #8245
    Avatar
    Ulrik Gorm

    How do I display the users avatar in the leader board?

    I have tried %avatar% but no luck.

    #8248
    Avatar
    WPExperts

    Hey.

    There is no built-in avatar template tag. It would be something you would need to add in and decide how big the avatar you want to use and any other customization you might want to add.

    So you can add as many custom template tags as you want and make them show anything you like.

    Here is a quick example of showing a 32×32 avatar image for each row in the leaderboard:

    add_filter( 'mycred_ranking_row', 'my_custom_ranking_rows', 10, 4 );
    function my_custom_ranking_rows( $layout, $template, $row, $position )
    {
    	$avatar = get_avatar( $row['ID'], 32 );
    	return str_replace( '%avatar%', $avatar, $layout );
    }
    

    Place the code snippet into your theme’s functions.php file and you can now use the %avatar% template tag. You can find more information on the get_avatar function in the WordPress Codex.

    #8249
    Avatar
    Ulrik Gorm

    Thanks.

    The avatar is now visible.

    #8274
    Avatar
    Ulrik Gorm

    Getting an odd error.

    I’ve just awarded points to all old users.

    And afterwards got a message: Trouble connecting til wordpress…

    Now the top admin has gone. But I can get it back by removing the avatar code from functions.php. Any idea what I’ve done wrong?

    #8303
    Avatar
    WPExperts

    Enable WP_DEBUG in your wp-config.php file and re-insert the code to see what errors you get (because you are getting them with those issues).

    Make sure you paste the code in correctly as is shown above and that you do not use some rich text editor to paste the code into before pasting it into your themes functions.php file. Some rich text editors will for example replace certain characters which will render an error in PHP.

    #11132
    Avatar
    Curtis

    Is there a way to make the avatars round instead of square?

    #11154
    Avatar
    WPExperts
    #11241
    Avatar
    Curtis

    Thanks for the quick responce. Im sorry but I’m not a coder so I’m still having trouble implementing that to the get avatar code you provided in this post?

    #11273
    Avatar
    WPExperts

    The link I sent you is a basic tutorial on how to make any image / item on your website to be round. You do it via CSS which you add to your theme’s style.css file.

    If you add in an avatar you will need to target those avatars with your css code. Example:

    li .avatar { border-radius: 50%; }
    

    Otherwise you can always use google and search: “CSS make image round”

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

11