So before I ask my question...
HEY EVERYONE, ANYBODY MISS ME?
Ok, so yea. I'm back in biz now and ready to keep on learning.
I'm not entirely sure if what I'm wanting to do should be done via the SQL query, or AFTER the query using PHP to filter the results...
Here's a rundown of what the following code already does versus what I want it to do:
The following code connects to the database that WP is installed in and accesses the "comments" table. It then makes a list of each person who has recently commented on the site (limit 16) and then runs their email address through a small snippet to verify whether or not they have set up an account with http://gravatar.com or not to determine what the alt/title text should read.
The SQL query filters out my admin email address so that I am not listed in the list of commentators.
All of this works perfectly. However, I need for it to also filter out any duplicate commentators from the list... In other words, if someone comments on the site more than once recently, it should only show their name in the list one time rather than XXX amount of times.
You can see it at work here: http://sexybookmarks.net/#all
Notice that there are several commentators who are listed more than once in the list... This is what I'm trying to get rid of.
PHP Code:
<?php
global $wpdb;
$comment_array = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' AND (comment_author_email <> '' AND comment_author_email <> 'my@admin_email_address.com') ORDER BY comment_date_gmt DESC LIMIT 16");
$comment_total = count($comment_array);
echo '<ul>';
for ($x = 0; $x < $comment_total; $x++) {
echo '<li>';
// Craft a potential url and test its headers
$comment_email = $comment_array[$x]->comment_author_email;
$hash = md5($comment_email);
$uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=identicon&r=any&size=80';
$headers = wp_get_http_headers($uri);
$getavatar = get_avatar($comment_email);
// Check the headers
if (!is_array($headers)) {
$has_valid_avatar = FALSE;
}elseif (isset($headers["content-disposition"]) ) {
$has_valid_avatar = TRUE;
}else {
$has_valid_avatar = FALSE;
}
if ($has_valid_avatar == "TRUE") {
$titletext = $comment_array[$x]->comment_author;
}
else {
$titletext = $comment_array[$x]->comment_author." hasn't signed up for a Gravatar yet!";
}
echo '<a href="'.$comment_array[$x]->comment_author_url.'" title="'.$titletext.'">';
echo get_avatar($comment_array[$x]->comment_author_email, 65);
echo '</a>';
echo '</li>';
}
echo '</ul>';
?>
Bookmarks