
After the rating is saved along with the comment into database, now it’s time to show that rating with the comment on the post page. This will also require modifying the theme files. And again, there is a couple of functions you will need to use. This integration is very easy for legacy WordPress comments file, but for the comments loop that support threads, it’s not that simple. Once again my Starscape theme is a good example for both methods because this theme supports both legacy and threaded comments.
Let’s start with standard (legacy) comments. Â Rendering of comments is done by the comment loop that uses similar principle as the post loop. I will use comments.php from WP 2.6.5 release. Loop block starts from the line 27 in this file with foreach loop that goes through all comments, and renders each one. Rendering is basically some HTML markup with few PHP functions for title, post author, comment text and few other things. All you need to do is to add call to a PHP function somewhere in this loop that will render saved rating. Line 39 in this file:
<?php comment_text() ?>
I will modify this to add rating value floated to the right. Styling is not important at this point, and you will need to do it yourself for your theme.
<?php if (defined("STARRATING_INSTALLED")) : ?>
<div style="float: right">
<?php wp_gdsr_comment_integrate_standard_result(get_comment_ID()); ?>
</div>
<?php endif; comment_text(); ?>
This code contains call for standard single rating. This function has several parameters, but only first one is required. This parameter is comment ID. Other parameters can be used to set different star set. If you used multi ratings, than you need to use different function. Multi rating call also require multi set id, and this set MUST be the same one used in the integration part. For displaying multi rating result you can use template. If you don’t specify this parameter, default one will be used. This type of rendering uses RMB (Multi Review Rating Block) template. Full list of parameters for each function you can find included with the plugin in the info folder, or click here. Here is the code example for multi rating with star set parameters:
<?php if (defined("STARRATING_INSTALLED")) : ?>
<div style="float: right">
<?php wp_gdsr_comment_integrate_multi_result(get_comment_ID(), 4, 0, "crystal", 16); ?>
</div>
<?php endif; comment_text(); ?>
If you leave template ID as 0, default template will be used.
Threaded comments introduced with WP 2.7 use a Walker class for rendering the comments. So, you will need to modify the Walker used by your theme. This is very different from theme to theme, and I can’t describe the process in many details. For default WP theme, this is a problem, because this theme uses built in Walker that you shouldn’t  change. The solution is to write new Walker class and use it. Starscape has it’s own Walker class, and this class is located in modules/comments_walker.php file in Starscape folder. StarscapeCommentWalker class is used by comments_new.php file. In this case, you also need to modify a class method that’s used to render each comment. This method is called start_el().
And, after all this you will have each comment author’s rating in the comment, and post will contain all the aggregated ratings. And, you can set up your own review website.
loading...




Comment Link
i thought that modyfing Walker will be difficult but it’s quite simple.you need to copy from Starscape theme files:comments.php,comments_new.php and modules/comments_walker.php
loading...
Comment Link
Yes, once you go through the Walker class, you can see that changes can be done easily. Hopefully, most of the other old WP code will be converted into classes in the next versions.
loading...
Comment Link
Could you please explain what you did? I’m trying to figure out how to implement this thing and am having major problems. I’m using the Atahualpa theme on WP 2.7.1
loading...
Comment Link
Sorry, but I don’t have free time to review every theme. The method I described is universal, but you need to figure out yourself whate and where to modify. Use my Starscape theme for reference. And there is always premium support.
loading...
Comment Link
I love this plugin, but I am completely lost as to where to insert the code so that the ratings show up on the posts (I’ve got it working on the comment form).
I have atahualpa theme installed, and I think my comment.php code might be a little different. Can you please explain a little bit more where to insert the code?
loading...
Comment Link
Lauren –
Just put [STARRATER] in the post where you want the rating block to show up.
OR
Put in the post template file where you want the stars/rating block to be.
loading...
Comment Link
It seems that the comment_integrated functions are not in the user manual. It would help if there were documented on a page somewhere in the mean time.
loading...
Comment Link
They are in the info files that come with the plugin.
loading...
Comment Link
I dont see a function to display the comment multirating aggregate on the post? I have it so each comment can make a multi-rating, and each comment is displayed with the multirating shown on the comment. But I don’t see how to display the “user rating” average, which I want to display before the comments are displayed.
loading...
Comment Link
I ended up doing this. Please let me know if there is a better way:
$r=wp_gdsr_rating_multi(1);
if ($r->rating > 0){
echo “Average User Rating\n”;
wp_gdsr_multi_rating_average(1);
echo ” ” . $r->rating . ” out of 5″;
}
loading...
Comment Link
You can duplicate MRB template, and only leave average rating stars, remove rating stars, and call the function for it with rating not allowed. Everything can be done using templates.
loading...
Comment Link
I’ve tried creating a new MRB template, but it doesn’t take. I can’t get templates to do anything.
loading...
Comment Link
Creating template is not enough. You must use it where you need it. That’s way you can make as many templates of the same type as you want, and use them through functions or shortcodes.
loading...