WordPress.org

Ready to get started?Download WordPress

Forums

using gravatar code elsewhere (24 posts)

  1. lokjah
    Member
    Posted 9 years ago #

    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?

  2. Nick Momrik
    Member
    Posted 9 years ago #

    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="" />";
    }

  3. lokjah
    Member
    Posted 9 years ago #

    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!

  4. Nick Momrik
    Member
    Posted 9 years ago #

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

  5. lokjah
    Member
    Posted 9 years ago #

    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"

  6. lokjah
    Member
    Posted 9 years ago #

    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

  7. lokjah
    Member
    Posted 9 years ago #

    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?

  8. lokjah
    Member
    Posted 9 years ago #

    any takers? :)

  9. Nick Momrik
    Member
    Posted 9 years ago #

    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.

  10. lokjah
    Member
    Posted 9 years ago #

    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?

  11. Nick Momrik
    Member
    Posted 9 years ago #

    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.

  12. Nick Momrik
    Member
    Posted 9 years ago #

    Whoops....make that $commenter, not $comment

  13. lokjah
    Member
    Posted 9 years ago #

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

    still showin up unpredictably....

  14. Nick Momrik
    Member
    Posted 9 years ago #

    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.

  15. lokjah
    Member
    Posted 9 years ago #

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

    http://www.pastebin.com/247706

  16. Nick Momrik
    Member
    Posted 9 years ago #

    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?

  17. lokjah
    Member
    Posted 9 years ago #

    yeah :) im doin that.... thanks for all the help man let me try what you just suggested....

    i think ultimately I would like to be able to impliment the gravatar independent from this plugin, just be able to show a gravatar where ever commenter info may be, eg, in a sidebar etc...

  18. lokjah
    Member
    Posted 9 years ago #

    ok removed the if block, but still willy nillyâ„¢ on the grav display...

  19. Nick Momrik
    Member
    Posted 9 years ago #

    Slaps forehead!!

    I just looked at the plugin and it's using the global variable $comment. This is the reason for your sporadic results. You could rename every occurrence of $commenter in your plugin with $comment and that should do the trick.

    I need to get away from the computer...lines are starting to blur. ;-)

  20. Nick Momrik
    Member
    Posted 9 years ago #

    lokjah,
    I emailed you custom version of the plugin that you can use anywhere, by passing the function an email address.

  21. lokjah
    Member
    Posted 9 years ago #

    u rock... do the dew!

    well we are getting somewhere now.... the other commenters gravs are showing correctly in addition to mine, however now we arent getting the default to show up...

  22. lokjah
    Member
    Posted 9 years ago #

    woot.. fixed that....just had the wrong file path this time....

    thanks again dew!

  23. Nick Momrik
    Member
    Posted 9 years ago #

    :-)

  24. 7milesdown
    Member
    Posted 9 years ago #

    MtDewVirus. Can you post the cleaned up coding here? This goes in the usercomments php right?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.