CyberKnowledge Technology Blog

Everything tech – reviews, tips, software, news

All tech all the time

Welcome to CyberKnowledge technology blog.

WordPress Plugin: Rate Your Comments (Comment Karma)

Posted by Alex Bailey On October - 15 - 2006

May 06, 2012 Update
This version of Comment Karma works for the newest version of WordPress 3.3.2. Thanks to Wealthy Netizen for picking up where I left off on a discontinued project.

DOWNLOAD Version 2.9.32


Comment Karma not working for you?

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).


After 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.

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.

Comment Karma 2.9.32
*Fixed for newer versions of WordPress
*Hide poorly rated comments
*Works with Wp-cache
*Choice of up and down arrows
*Better voter fraud detection

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

Newest version has one click install!

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(); ?>

Skip to this step:

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

Download
Comment Karma 2.9.32
Broken on newer WordPress installs:
Comment Karma 2.0
Comment Karma 1.1

Thanks to
Bawked – Wrote the ajax, and debugged the PHP.


See also...

43 Responses to “WordPress Plugin: Rate Your Comments (Comment Karma)”

  1. Rub3X says:

    This is a test comment, so you can see the ratings. Enjoy!

  2. Ian Harris says:

    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 says:

    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 says:

    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 says:

    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 says:

    [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 says:

    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. 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.

  9. 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
    }

  10. wrongling says:

    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).

  11. 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

  12. KC says:

    When I installed it first time, the images were grayed out. Turns out I did not create sub directories (images and RCS) in plugins directory while uploading to the server. Make sure you follow the directory structure in the zip file

  13. MikeonTV says:

    Why is it that the newest version is not the same template as what we have in this discussion?

    I would like to have the two vote buttons and then the tallied number next to it rather than how many up votes next to the thumb up and how many downs next to the thumb down. Can you specify how to do this?

  14. Sally says:

    When I installed it first time, the images were grayed out. Turns out I did not create sub directories (images and RCS) in plugins directory while uploading to the server. Make sure you follow the directory structure in the zip file

    - I’m getting the same problem as Raj did. I have the folders “images” and “RCS”, but inside the ck-karma directory, not inside its parent (which is plugin) dir.

    Why? Is it because I’m testing it locally (localhost/127.0.0.1)? :P If so, what should I do to fix the problem?

  15. SPiHC says:

    I’ve noticed a few different people ask if it would be possible to sort the comments by current rank.

    I was wondering if it’d be possible to take Alex Schleber’s addition there and modify it into a top 10 / top 5 listing?

    Cheers,
    SPiHC

  16. drew3000 says:

    Got it to show up with a little tinkering (plus my theme’s calls are different from the usual) but it’s not really allowing people to actually vote. It just shows up. The curser ctivates when hovering over but when you click thumbs up or down, nothing changes. Anyone have anything similar?

  17. MitchMoore says:

    Any help available… I installed the plugin as directed. Everything shows up and it seems to be fine, but when I try to vote up or down it doesn’t do anything?

    Even the ones for the comments on this page wont let me vote… I get an error msg on this page, but nothing on mine.

    I just upgraded to WP version 2.6.5 anyone have an ideas or suggestions? THX!!

  18. magic says:

    everything is possible. btw, alexes method is for karma 1 and to the old database structure. Also the first function would be enough. You could also take alexes mathod and have it return the comments so you could loop through that and have the comments sorted by most rated etc.

  19. Peter says:

    How can this be integrated into WordPress 2.7 comments ?

    As there is no “foreach” anymore.

    Thanks.

  20. Michael says:

    Hey, I got a problem, nothing big, just annoying: If someone rates a comment the space between the icon and the current score disappears and everything right to the icon slips a few pixels to the left. Has anyone an idea how to avoid that?

    Thanks, Michael

  21. Many thanks for this superb plugin.

    Will be interested to learn the compatibility with 2.7 though.

    Is there anyway i can call a list of the most voted comments?

  22. Bawked says:

    holy shit my inbox still gets hit by this…… i might tweak it to work with 2.7 for those out there.

  23. Trina says:

    @ BAWKED – That would be so great if u made it work! I’ve been wanting this feature for awhile but the plugin was buggy with the new versions of WP!!!

  24. Trina says:

    @ BAWKED – That would be so great if u made it work! I’ve been wanting this feature for awhile but the plugin was buggy with the new versions of WP!!!!

  25. Peter Pan says:

    hey, I just installed this on my blog, 2.6.3 WP, but when I vote myself or someone else, nothing happens at all. I’m sure i installed it as I did it carefully, everything shows etc, just nothing happens…. any luck anyone? thanks

  26. Suzanne says:

    The vote images are above the names and comment… How do i fix this?

    Where would I put ck_display_karma();

  27. Robert says:

    I was searching for comment karma plugins and ran across this site. It would be nice if you could work it out for WP2.7. I’ll check back later.

  28. FertSoft says:

    nice plugin! THX 2 authors!

  29. kanoner says:

    I wish you would, this is a function I have been looking for for some time. Hav tried it before without beeing able to get it to work ;)

  30. Greg Johnson says:

    I would love to see this for WP 2.7

  31. Paul says:

    I’m having no luck with this.

    Am I placing the code in the wrong part of the loop?

    Exactly where does it need to be pasted?

    Thanks in advance! I’m using 2.7, so I’m not sure if that’s the issue or not?

  32. roman says:

    Too bad it doesn’t work with WordPress 2.7.1
    It would have been cool!

  33. Blake K says:

    Would it theoretically be possible to do some kind of ajax modification so that the comment rating grays out after use even if you’re using super cache? It’s hard to “teach” people to use this awesome plugin if they can’t see it working.

  34. Laurence says:

    I’d be interested in using this plugin in WP 2.7 — IntenseDebate is just too flaky, and DISQUS is downright ugly/inelegant.

    Something simple would be great, as the core WP commenting system is fine IMO and just needs a couple of extras to make it really great.

  35. Matt says:

    Didn’t work for me. I followed all the instructions but when I installed to my blog and clicked on the vote buttongs, it gave me “object not found” javascript errors.

  36. Justin says:

    For the people who said everything shows up properly but you cannot vote up or down – you simply copied and pasted the code given in the blog into your header and didn’t change it. Just replace “domain” with your domain name.

  37. Blake K says:

    I am very interested in getting this to work in a wp-cache/supercache environment. Even conceptually, can someone think of a way? I mean, I know it “works”, but since it doesn’t provide feedback to users in a cached context, they probably won’t use it. Isn’t there some way around this using ajax even on a high-traffic server?

  38. xtraa says:

    yea, tweak it baby :)

    really this plugin would be the shiz if you would bring it to the new version. AM everything is fine except it doesn´t count votes :D

    thanks in advance!

  39. Brett says:

    Can you tweak for 2.8?

  40. Marcus says:

    Hi! Nice plugin. But, I am using WP 2.8 and later 2.8.1, so is there a way to make the plugin ready for WP 2.8+ ???

  41. The Awful Truth says:

    LOL! This plugin seems to be abandoned… the author of it doesnt seem to care about us fans of it. He didn’t made it work for 2.7 and he will not make it work for 2.8! It’s obvious! :(

    I want so much a plugin for comment ratings (YOUTUBE STYLE) thumbs up/thumbs down, but I can’t seem to find any…

  42. Alex Bailey says:

    Plugin now works for newest WordPress version: 3.3.2.

Leave a Reply