Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

User Photo in Get Recent Comments Widget WordPress


I want to put the [[LINK href=""]]User Photo[[/LINK]] into the widget of recent comments which is made with this [[LINK href=""]]plugin[[/LINK]].

I could not figure out any other way to get two plugins together, which harmonize.

As i suggest, one has two write a macro-function, which Get Recent Comment makes use of. This function should generate the thumbnail of the user photo.

Or you could simply find a way to use php tags in the template for the recent comments.

Answers (3)


B L answers:

The recent comments plugin suggests using the [[LINK href=""]]profile pic plugin [[/LINK]] and then using the %profile_picture macro to insert the author images. This is probably the easiest if you don't want to get your hands dirty in the code.

You will not simply be able to use userphoto_comment_author_thumbnail() because that will echo the images directly to the HTML stream rather than append the string to the output variable that the recent comments plugin uses....... Thus your images will not end up where you want them to be.

A quick and dirty hack if you want to continue to use the user photo plugin would be to edit the recent comments plugin code. On line 1380, change:
$output = str_replace("%profile_picture", '', $output);
$output = str_replace("%profile_picture", userphoto__get_userphoto($comment->user_id, 2, '','','',''), $output);

(note the double underscore instead of single)
Then go back to your recent comments settings and add in the %profile_picture macro in the location you want the picture to end up.

B L comments:

You cannot simply use userphoto_comment_author_thumbnail() because it will echo the images directly rather than concatinate a string to the output variable the recent comments plugin requires.

You could put a bit of a dirty hack in by changing line 1380 from
$output = str_replace("%profile_picture", '', $output);
$output = str_replace("%profile_picture", userphoto__get_userphoto($comment->user_id, 2, '','','',''), $output);

Then put the %profile_picture macro in the settings of the get recent comment plugin at the point you want it to display

Alternatively, use the [[LINK href=""]]profile pic[[/LINK]] plugin suggested in the get recent comments plugin and add the %profile_picture macro

phil wars comments:

ok. i try that! sounds good! I also tried Profile Pic-plugin which produces an error when uploading the profile pic:

<blockquote>Warning: Invalid argument supplied for foreach() in /www/htdocs/w00bfdc8/wp-content/plugins/profile-pic/profile-pic.php on line 422

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/w00bfdc8/wp-content/plugins/profile-pic/profile-pic.php:422) in /www/htdocs/w00bfdc8/wp-includes/pluggable.php on line 868</blockquote>

Could you mess two more macros for me?

phil wars comments:

ok. works.

how can i change this line

if (empty($author_url) || $author_url == "http://")


if (empty($author_url) || $author_url == "<strong>BLOGURL/profile/user-nicename</strong>")

phil wars comments:

AND: unfortunately the widget does not show anything, when a user is not registered. Is there a way to do that?


Ehthisham tk answers:

this code will display recent comment with the author's gravatar no plugin needed
$total_comments = $wpdb->get_results("SELECT comment_date_gmt, comment_author, comment_ID, comment_post_ID, comment_author_email FROM $wpdb->comments WHERE comment_approved = '1' and comment_type != 'trackback' ORDER BY comment_date_gmt DESC LIMIT 10");
$comment_total = count($total_comments);
echo '<ul>';
for ($comments = 0; $comments < $comment_total; $comments++) {
echo "<div style='clear:both;width:355px;padding-top:3px;'><div style='float:left;width:35px;'>";
echo get_avatar($total_comments[$comments]->comment_author_email,$size='32',$default='<path_to_url>' );
echo "</div> <div style='width:320px;'>";
echo '<li>';
echo $total_comments[$comments]->comment_author . ' says ';
echo '<a href="'. get_permalink($total_comments[$comments]->comment_post_ID) . '#comment-' . $total_comments[$comments]->comment_ID . '">';
echo get_the_title($total_comments[$comments]->comment_post_ID);
echo '</a></li></div></div>';
echo '</ul>'

phil wars comments:

Ok this would take a lot of effort to implement this.


So i must put in like that: userphoto_comment_author_thumbnail()

I'll try...

Ehthisham tk comments:

yea sure.You can also try this if the user has no userphoto then display the gravatar

echo get_avatar($user->ID, 96);


SmashinGeeks answers:

What I suggest you in order to get recent comments with gravatar is that, you should use this plugin.

[[LINK href=""]]Recent Comments By Rob Marsh[[/LINK]]

After downloading the plugin, activate it and jump to Recent Comments Option usder Settings tab. And then go to "Output" link under the heading. In the output code, place this code :

<img src="{gravatar}" width="50" height="50" alt="" />{link}
<div class="clear"></div>

You can choose custom size of the gravatar.Also you can spice it up with some CSS code :

#recent-comments h3 { font-size: 1.8em; letter-spacing: normal; padding-top: 15px; }
#recent-comments{ float: left; width: 50%; }
#recent-comments p { margin-bottom: 15px; padding: 10px 2.5em 10px 10px; }
#recent-comments a { font-size: 1.4em; border-bottom: 1px solid #CB3131; line-height: 1.5em; }
#recent-comments a:hover { border: 0; }
#recent-comments h3 { padding-left: 10px; }