Is there anyway to add gravatar images to recent comments, i was messing with the template funcions.php file, but i can only get the default gravatar too print out and not individual ones?
This is my implementation, i can get it to show the default image, but not the user with a gravatar? the original pieces of code can be found at the bottom
I know nothing of gravatar, however I can tell you from your code that if it is only displaying the default image then there is some problem with the gravatar_id bit. Maybe passing the md5 of the email address is not sufficient or not correct.
This is how they state to do it on their web page.
PHP
Implementing gravatars with PHP is quite simple. PHP provides strtolower(), md5(), and urlencode() functions, allowing us to create the gravatar URL with ease. Assume the following data:
` $email = "someone@somewhere.com"; $default = "http://www.somewhere.com/homestar.jpg"; $size = 40; ` You can construct your gravatar url with the following php code:
` $grav_url = "http://www.gravatar.com/avatar.php? gravatar_id=".md5( strtolower($email) ). "&default=".urlencode($default). "&size=".$size; ` Once the gravatar URL is created, you can output it whenever you please:
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5( strtolower($email) )."&default=".urlencode($default)."&size=".$size; echo $grav_url; } ` I put this in a file called customfunctions.php within my theme folder and you would call it like this ` "> `
Comments
`
function printLatestComments($number, $shorten='123') {
if(getOption('mod_rewrite')) {
$albumpath = "/"; $imagepath = "/"; $modrewritesuffix = getOption('mod_rewrite_image_suffix');
} else {
$albumpath = "/index.php?album="; $imagepath = "&image="; $modrewritesuffix = "";
}
$email = getCommentAuthorEmail();
$comments = getLatestComments($number,$shorten);
echo "
echo "
\n";
- ".$author."
";
\n";foreach ($comments as $comment) {
if($comment['anon'] === "0") {
$author = " ".$comment['name'] .gettext(" said: ")." ";
} else {
$author = "";
}
$album = $comment['folder'];
if($comment['type'] === "images") {
$imagetag = $imagepath.$comment['filename'].$modrewritesuffix;
} else {
$imagetag = "";
}
$date = $comment['date'];
$albumtitle = $comment['albumtitle'];
if ($comment['title'] == "") $title = $image; else $title = get_language_string($comment['title']);
$website = $comment['website'];
$shortcomment = truncate_string($comment['comment'], $shorten);
if(!empty($title)) {
$title = ": ".$title;
}
$default = "http://www.thehilln10.com/images/defaultGrav.gif";
$size = 20;
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&default=".urlencode($default)."&size=".$size;
echo "
\n";
echo "".$shortcomment."
echo '';
}
echo "
echo "
}
`
The original gravatar hack:
`
<?php
$email = getCommentAuthorEmail();
$default = "http://www.thehilln10.com/images/defaultGrav.gif";
$size = 40;
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&default=".urlencode($default)."&size=".$size; ?>
" alt="" class="gravatar" />
`
The original print latest comments code:
`
function printLatestComments($number, $shorten='123') {
if(getOption('mod_rewrite')) {
$albumpath = "/"; $imagepath = "/"; $modrewritesuffix = getOption('mod_rewrite_image_suffix');
} else {
$albumpath = "/index.php?album="; $imagepath = "&image="; $modrewritesuffix = "";
}
$comments = getLatestComments($number,$shorten);
echo "
echo "
\n";
- ".$author."
";
\n";foreach ($comments as $comment) {
if($comment['anon'] === "0") {
$author = " ".$comment['name'] .gettext(" said: ")." ";
} else {
$author = "";
}
$album = $comment['folder'];
if($comment['type'] === "images") {
$imagetag = $imagepath.$comment['filename'].$modrewritesuffix;
} else {
$imagetag = "";
}
$date = $comment['date'];
$albumtitle = $comment['albumtitle'];
if ($comment['title'] == "") $title = $image; else $title = get_language_string($comment['title']);
$website = $comment['website'];
$shortcomment = truncate_string($comment['comment'], $shorten);
if(!empty($title)) {
$title = ": ".$title;
}
echo "
\n";
echo "".$shortcomment."
}
echo "
echo "
}
`
I have used Gravatar in BBpress with great results.
here is some info about code.
http://en.gravatar.com/site/implement
This is how they state to do it on their web page.
PHP
Implementing gravatars with PHP is quite simple. PHP provides strtolower(), md5(), and urlencode() functions, allowing us to create the gravatar URL with ease. Assume the following data:
`
$email = "someone@somewhere.com";
$default = "http://www.somewhere.com/homestar.jpg";
$size = 40;
`
You can construct your gravatar url with the following php code:
`
$grav_url = "http://www.gravatar.com/avatar.php?
gravatar_id=".md5( strtolower($email) ).
"&default=".urlencode($default).
"&size=".$size;
`
Once the gravatar URL is created, you can output it whenever you please:
`
function gravatar($email) {
$default = "http://www.somewhere.com/homestar.jpg";
$size = 60;
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5( strtolower($email) )."&default=".urlencode($default)."&size=".$size;
echo $grav_url;
}
`
I put this in a file called customfunctions.php within my theme folder and you would call it like this
`
">
`
I don't follow, I don't seem to get this to work that way....
After a long try the only thing I get is empty photo.