Fork me on GitHub

Sunday, April 15, 2007

Blog / Adding Gravatars to FlatPress

Adding Gravatars to FlatPress

Yeah, I know it’s not this big discovery, I already knew Gravatar, but I didn’t know they were so easy to implement.

What is a gravatar?

A gravatar, or globally recognized avatar, is quite simply an 80×80 pixel avatar image that follows you from weblog to weblog appearing beside your name when you comment on gravatar enabled sites. Avatars help identify your posts on web forums, so why not on weblogs?

First, register to

Choose your Gravatar.

Then, open your theme’s comments.tpl

Find the lines between {comment}{/comment} tags.

Paste in the following, after the
{include file=shared:commentadminctrls.tpl} and before the {$content}

<img class="avatar"
alt="Avatar for {$name}" title="Avatar for {$name}" width="40" height="40" />

Of course you can paste it anywhere else, even though it must stay between the {comment} block.

Paste then this to your style.css (or something along the lines… it’s your taste, at this point)

img.avatar {
        margin: 10pt;
        padding: 2px;
        border: solid #ddd 1px

You’re done :)

You can find more info on what parameters you can pass to the img src url reading here:

I’ve also managed to have an hack for SPB, if you’re interested. But it’s very hackish :/

Open sb_comments.php, then search for the line saying

'if ( isset( $comment_entry_data[ 'EMAIL' ] ) ) { 
/* other stuff here */ 

after that line, paste this

// yeah, this way I'm doing the isset twice, 
// but at least instructions are simpler for you
 $comment_email = isset($comment_entry_data['EMAIL'])? $comment_entry_data['EMAIL'] : '';
                $grav_url = "".md5($comment_email)."&size=40"; 
                $avatar = "<img class=\"avatar\" src=\"$grav_url\" alt=\"Avatar for $name\"".
                          "width=\"40\" height=\"40\" title=\"Avatar for $name\" />";

then, you’ll have a bunch of $blog_entry[’…’]; change the last one (”$entry_array[ ‘entry’ ]”) into the following

$entry_array[ 'entry' ] = $avatar . blog_to_html( $comment_entry_data[ 'CONTENT' ], true, false, true, true ) . '<br clear="all" />';

It looks like there’s no cleaner way :/

Bye :)