Support » Plugins and Hacks » using gravatar code elsewhere

using gravatar code elsewhere

  • Im trying to incorporate the gravatar code in other areas of my site and seem to be havin a bit of trouble getting it to show up…. at the moment i’m trying to add it to the get-commenters code by coffee2code and after alot of attempts the closest I can come is getting no php errors but its printing out the last bits of the img src
    bruce" alt="" /> (2)

    when using the gravatar code as such :

    foreach ($commenters as $commenter) {
    echo $before;
    if (!empty($commenter->comment_author_url)) echo '<a title="Visit ' . $commenter->comment_author . ''s site" href="' . $commenter->comment_author_url . '"';
    if ($open_in_new_window) echo ' target="_blank"';
    if (!empty($commenter->comment_author_url)) echo '>';
    echo $commenter->comment_author;
    if (!empty($commenter->comment_author_url)) echo '</a>';
    if (!empty($commenter->comment_author_url)) echo '<img src= "<?php gravatar("G", 50, "http://mysite.com/graphics/grav.gif"); ?>" alt="" />';
    if ('top' == $type) echo ' (' . $commenter->total_comments . ')';
    if (!$omit_last_after) echo $after;
    echo "n";

    anyone spot what Im doin wrong?

Viewing 15 replies - 1 through 15 (of 23 total)
  • The gravatar plugin code already does an echo, so you can’t echo the echo.

    Try changing
    if (!empty($commenter->comment_author_url)) echo "<img src= "<?php gravatar("G", 50, "http://mysite.com/graphics/grav.gif"); ?>" alt="" />";

    to this
    if (!empty($commenter->comment_author_url)) {
    echo "<img src= "";
    gravatar("G", 50, "http://mysite.com/graphics/grav.gif");
    echo "" alt="" />";

    thanks a ton man…. never would have figured that out…

    only thing now is im getting erratic results on what gravatar is showing up…. im using this code in a sidebar and when the main index page is viewed I get the generic gravatar (used for commenters with no gravatar) for all commenters. then when viewing an actual post I can see my custom gravatar shows up, but in some instances it is also being used for other commenters, and in other cases other commenters have no image at all…..

    could it be how the gravatar code is written in your example or maybe something else?

    thanks again woot!

    I had left off the closing backtick for the code block. Try the code again.

    hmm I get a parse error with this code

    if (!empty($commenter->comment_author_url)) {
    echo "<img src= "";
    gravatar("G", 50, "http://www.mysite.com/graphics/grav.gif");
    echo "" alt="" />";

    “Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘,’ or ‘;’ in /home/aenonf2/public_html/afd/blog/wp-content/plugins/get-commenters.php on line 106”

    using your first code:

    if (!empty($commenter->comment_author_url)) {
    echo '<img src= "';
    gravatar("G", 50, "http://www.mysite.com/graphics/grav.gif");
    echo '" alt="" />'; }

    works but the gravatar results are sporadic as noted above

    using single quotes works but double does not, while the single ones work could it be borking the way the gravatar gets the author info?

    any takers? 🙂

    if (!empty($commenter->comment_author_url)) {
    echo '<img src= "';
    gravatar("G", 50, "http://mysite.com/graphics/grav.gif");
    echo '" alt="" />';

    I think bbPress ate the code. This one should work.

    well thanks alot for your help mtdv, that code indeed works with no php errors, just still get unpredictable gravatar results, eg, on the index page it shows the default gravatar for everyone, on a post page it shows my custom gravatar for me as well as other posters, and on other posts it will show my custom gravatar and no gravatar for other commenters.

    is there a way maybe I could write the gravatar code by itself apart from the get commenters plugin?

    I don’t know how I missed this before, but instead of
    if (!empty($commenter->comment_author_url)) {
    it should be
    if (!empty($comment->comment_author_email)) {
    since gravatars are linked to email address, not URL. Try changing that line and see what happens.

    Whoops….make that $commenter, not $comment

    huh very strange man.. u know that didnt make a lick a difference…..

    still showin up unpredictably….

    Is the plugin pulling comment_author_email in the query to the database? Maybe you can paste the code up here…
    http://www.pastebin.com/ and post back here with a link to it.

    hope i did this right man.. heres the link to the plugin code


    I don’t know what to tell you. I can’t see anything jumping out at me. Only thing I can think of is to remove the if block around that gravatar code, because now that I think of it, the if isn’t needed. Gravatar should work with or without an email address passed to it. If it doens’t get one, it simply displays your default image.

    By the way…you are replacing “http://mysite.com/graphics/grav.gif” with the location of your own default image right?

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘using gravatar code elsewhere’ is closed to new replies.