WordPress Plugin: Rate Your Comments (Comment Karma)
October 15th, 2006 - By: Alex BaileyAfter searching Google for a few minutes for a comment karma/rating plugin for WordPress I was amazed I couldn't find one. So I read through WordPress documentation for a bit, and dug in.
Since a large number of people are both successful and in need of assistance, I can't and don't have enough time to help everyone. If you're willing to pay a small donation for me to install or modify the plugin on your blog use the contact form. You may also email th3rub3x|@|gmail[dot]com (same as paypal).
Comment Karma 1.1 Release
Fixed:
*Security issue.
*Hovering over the images gives you a mouse cursor now.
Comment Karma 2.0 Release
Fixed:
*Security issue.
*Better MySql queries and table indexing to increase performance.
*Allows you to see how many times a comment has been modded up, down, and the total.
*No longer displays to negative signs when a comment is below zero.
*When upgrading to 2.0 your existing comment karma count will be lost due to the new database structure. This is because it's now tracking both up and down votes, and before it was just adding and subtracting from one number.
What is it
This is a plugin for WordPress blogs that allows users to rate or moderate other users comments. You can click thumbs up or down, and it will give them a positive or negative number. Basically the exact same thing you'll find on Digg or Slashdot.
Issues
Currently there are no known issues, it works like a charm. If you're using WP-Cache or similar the icons will not show up gray, nor will the numbers be updated if you reload the page until the page expires. However if a user votes again it will throw them an error. I've worked around this by setting the cache for 120 seconds. That way the server doesn't get hammered with SQL queries, but you still see the comments being moderated in almost real time.
If you're having trouble installing 2.0 from 1.1, try deactivating the plugin, deleting the files and reupload them. Proceed to PHPMyAdmin and drop the ck_karma table. (Sorry, it's the only way). Then enable the plugin and use it as you normally would.
Installation
Unzip the folder you downloaded, and upload the whole thing in to your plugins directory. You'll need to edit your header file, and add:
<script type="text/javascript" src="http://domain/wp-content/plugins/ck-karma/ck-karma.js">
</script>
I added mine directly under the head tag. Next depending on your theme you need to edit your comments theme file. You need to add ck_display_karma(); in your comment's for each loop. Look for "foreach ($comments as $comment)". You can insert it in that loop. Mine happens to be here:
<?php if (comment_subscription_status()) { echo " (subscribed to comments) "; } ck_display_karma(); ?>
Lastly enable it via plugins page. That should install all the needed tables.
Questions? Comments? Bugs?
If you have questions about installing or using it you can post a comment on this post. This is so people having the same issues can easily get the fix. If you're willing to pay a small donation for me to install or modify the plugin in any way use the contact form. You may also email th3rub3x|@|gmail[dot]com (same as paypal).
Download
Comment Karma 2.0
Comment Karma 1.1
Thanks to
Bawked - Wrote the ajax, and debugged the PHP.
Hey even a few dollars helps!
Enjoy - Rub3X and Bawked!




















1. Rub3X | October 15th, 2006 @ 8:52 AM |
+767
This is a test comment, so you can see the ratings. Enjoy!
2. Ian Harris | October 22nd, 2006 @ 10:15 AM |
+45
Hello. I wonder how hard it would be to rank the comments according to their rating? So poor comments get buried and good comments rise to the top. I guess it would be difficult?
3. Raj | November 4th, 2006 @ 6:09 AM |
+9
Hi,
I have activated this on my new site; keepreadingus.com [using wp v2.0.5], but the voting images are always grayed out. Why is this so?
Does the plugin take into account the IP of the machine fromw hich the commpent is posted from?
Or is this some kind of error that needs to be fixed. I even tried logging out and checked, but they ares till grayedout.
Thanks for any help.
4. josh | January 9th, 2007 @ 1:02 AM |
+3
Hey, great plugin. I’m wondering if there is a function to get the highest rated comment for a post? So when I display a link to a post I can also include some, if not all of the highest rated comment. Any thoughts? Also, and I think you may be adding this to the new build, but I’d like to sort the comments from highest to lowest for a particular post. Thanks again!
5. Jason | January 23rd, 2007 @ 5:21 AM |
+2
Is there anyway to make this so it does not check IP’s per rating. I am in college and many of my sites visitors are from my college, which only has one external IP address due to the way the network is setup. Thus only one person can make a rating on the posts, and all others are blocked from doing it.
Thanks
6. Alex Bailey | January 23rd, 2007 @ 9:02 AM |
+3
[quote comment="7559"]Is there anyway to make this so it does not check IP’s per rating. I am in college and many of my sites visitors are from my college, which only has one external IP address due to the way the network is setup. Thus only one person can make a rating on the posts, and all others are blocked from doing it.
Thanks[/quote]
Comment out this line
$ck_ips = $row['ck_ips'] . getenv(”REMOTE_ADDR”);
In ck-processkarma.php. A comment is // in front of the line by the way. Everyone will be able to vote unlimited amounts of times if you do this.
7. James | February 14th, 2007 @ 2:06 AM |
+2
How hard would it be to modify this seemingly very cool plugin to allow the readers to rate the posts as well as the comments?
And will there be any way of “easily” administering the images used for up.png and down.png? Having that feature in the options section (I’ll assume there is one) would be sort of cool.
Thanks.
8. Bawked | February 7th, 2008 @ 8:33 AM |
+1
coderweb.n...%201.2.zip <- small fix
9. Alex Schleber | May 12th, 2008 @ 5:03 AM |
+5
Hi,
I was wondering how the “bury” is actually implemented, since I couldn’t find anything about it in your plugin code.
As a quick hack, I added a function to ckarma.php:
function get_cmt_karma($id) {
global $ckarma;
$karma = $ckarma->getKarma($id);
return $karma;
}
that I then call in my comments (foreach) loop right at the top:
$karma = get_cmt_karma(get_comment_id());
if ($karma < -9) continue;
So we skip over “buried” comments with ratings of -10 or less; set your own threshold here.
Then you can also use this as a qualifier when writing the comment header info to turn off e.g. a DoFollow link for a spammy comment.
Anyway, hope someone finds this useful, I would still be interested if there was some sort of implementation of the “bury” that I overlooked.
I too am working on a way to get the top comment for a post, easiest would likely be to add a field ck_post_id to the table and save this on “insert”. Else it’s going to have to be a pretty messy (and slower) join of the wp_comments and wp_ckTbl_ tables.
Thanks for the great plugin.
10. Alex Schleber | May 12th, 2008 @ 5:08 AM |
+3
Here is the example code for the DoFollow link suppression on spammy comments (note that the threshold for this would be set to lower than for “bury”
if (get_comment_author_url() && ($karma > -5)) {
display comment_author() inside of comment_url() link …
} else {
display comment_author() only
}
11. wrongling | May 15th, 2008 @ 4:47 PM |
+1
Thanks for the extra code snippets everyone - this plugin has so much potential. How difficult would it be to highlight every comment rated above a certain threshold with a css style? (ie every comment rated +20 or above gets a colored background to highlight it, or an icon, gold star, etc).
12. Alex Schleber | May 16th, 2008 @ 11:45 PM |
+12
I finally got around to creating the function to return the top-rated comment
for a given post:
function get_top_comment($postId) {
global $wpdb;
$sql = “SELECT comment_ID, comment_date, comment_author, comment_author_url, comment_content, SUM(ckTbl_rating) AS ratings_total
FROM wp_ckTbl_commentMain, wp_comments
WHERE ckTbl_comment_id = comment_ID
AND comment_post_ID = $postId
GROUP BY ckTbl_comment_id
ORDER BY ratings_total DESC, comment_date ASC;”; // the date is the tie-braker, earlier comment wins
$comments = $wpdb->get_results($sql);
$topcmt = $comments[0]; // take the top-most one, we have sorted for it to be the top comment
if (!$topcmt->comment_ID) $topcmt=0; // if it’s not set, return 0
return $topcmt;
}
in ckarma.php:
function get_top_comment($postId) {
global $ckarma;
$topcmt = $ckarma->get_top_comment($postId);
return $topcmt;
}
then use
$topcmt = get_top_comment(get_the_ID());
$topcmt->comment_author
and so forth in e.g. the while(have_posts()) loop in your index.php to do stuff with the top comment, or place elsewhere in your templates or custom widgets.
Watch this function in action on my blog:
businessmi...dhacks.com
(top comment excerpt with DoFollow link displayed if present for every post on the index page)
Best - Alex
Leave a comment