Display author avatars by post title

Sep 18, 2009 at 3:47 PM

Is there any way to display an avatar of the author up by the post title and 'By author'?

Sep 21, 2009 at 1:52 PM

In your theme's PostView.ascx, add this function and then call it anywhere in the markup where you want to display avatar: <%= Gravatar(50) %>.

<script runat="server">
    protected string Gravatar(int size)
        string GRAVATAR_IMAGE = "<img class=\"photo\" src=\"{0}\" alt=\"{1}\" />";

        string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(Post.AuthorProfile.EmailAddress.ToLowerInvariant().Trim(), "MD5").ToLowerInvariant();
        string gravatar = "http://www.gravatar.com/avatar/" + hash + ".jpg?s=" + size + "&amp;d=";

        string link = string.Empty;
        switch (BlogSettings.Instance.Avatar)
            case "identicon":
                link = gravatar + "identicon";

            case "wavatar":
                link = gravatar + "wavatar";

                link = gravatar + "monsterid";

        return string.Format(System.Globalization.CultureInfo.InvariantCulture, GRAVATAR_IMAGE, link, Post.Author);



Sep 21, 2009 at 3:31 PM

Thanks Rtur.

Our authors arent setup with gravatar yet, and I'm unfamiliar with how it links. Do we just need to setup gravatar accounts with the same email that the blog account has? Is gravatar the easiest way to do this, or can we host them locally?


Also, I've looked around, but what file do I need to edit to control what appears on the basic posts, both on the main page and the single post page?


Sep 21, 2009 at 6:29 PM

The Gravatar is probably the easiest way to set up your authors personal image, it is based on email and will be shared across BE and many other blogs where you write a comment.

Check out this post to understand what goes where in the theme you are using.