GD Star Rating: Comment integration with WordPress 3.0

GD Star Ratings is a great plugin IF you look past the excess javascript and CSS (which you can easily disable). Why just “okay”? The documentation is out of date by at least 3 years at the time of this writing. It’s also a heavyweight plugin for sure – not something you want to use on a shared server.

The simplest tasks require you to dig through the plugins functions, and you really do have to spend some time familiarizing yourself with the plugin.

Inserting GD Star Ratings into comment_form

WordPress 3.0 replaced the comment form template with the function comment_form. To add multi-sets or standard ratings manually to the comment form is now an entirely different process. The trick is to use $echo=false when modifying comment_form.

Here is what I replaced comment_form() with to insert a multi-rating block in my theme (comment_form is likely called from the template “comments.php”):

<?php
$form_args = array( 
	'title_reply_to' => __('Reply to %s'), 
	'title_reply' => __('Post a Review'), 
	'comment_field' => wp_gdsr_comment_integrate_multi_rating($multi_set_id = 1, $template_id = 0, $value = 0, $stars_set = "oxygen", $stars_size = 24, $stars_set_ie6 = "oxygen", $echo = false).'<p class="comment-form-comment"><label for="comment">My Review</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>',
	'comment_notes_after' => __('')); 
comment_form( $form_args );
?>

This will add the multi rating block before the textarea and allow you to adjust your textarea label/class. The above code will use the stars set “oxygen” at 24px and multi set “1”.

Replace wp_gdsr_comment_integrate_multi_rating with: wp_gdsr_comment_integrate_standard_rating to display standard ratings


Display Rating Results in Comments

After you have added your rating block to comments, you will want to display the ratings alongside the comment. I am using my reviews in a custom post type, and I don’t display multi sets on posts, so what I did I create a copy of my comments.php and renamed it reviews.php. I then changed twentyten_comments() to twentyten_reviews.

Inside of your functions.php, create a copy your existing comments callback twentyten_comments and rename to twentyten_reviews. If your site only displays multisets, you can just modify twentyten_comments.

Somewhere within your comments callback, you will add:

<?php // Display multiset rating results
 wp_gdsr_comment_integrate_multi_result($comment_id = get_comment_ID(),$multi_set_id = 1, $template_id = 1,$stars_set = "oxygen", $stars_size = 24, $stars_set_ie6 = "oxygen"); ?>

or

<?php // Display standard rating results
 wp_gdsr_comment_integrate_standard_result($comment_id = get_comment_ID(),$multi_set_id = 1, $template_id = 1,$stars_set = "oxygen", $stars_size = 24, $stars_set_ie6 = "oxygen"); ?> for standard ratings

Note: I wrote this post after being awake for over 24 hours and sitting at the ER waiting for a friend. I will try to rewrite this ASAP, but I cannot guarantee that I will. YMMV! If you have any questions, just ask!

This entry was posted in Wordpress. Bookmark the permalink.

31 Responses to GD Star Rating: Comment integration with WordPress 3.0

                Leave a Reply

                Your email address will not be published. Required fields are marked *