WordPress Plugins > WP-PostRatings

Display only stars (no text, no votes allowed)

(1/1)

infomancer:
Hello,
 I am looking for a way to show only the current rating of the post (no voting allowed) in the custom loop I did for top rated posts. But I don't want to modify "Ratings Vote Text" since I'm using it for regular posts.

Basically the same static "stars" that are shown in the widget and it the comment author ratings. In the templates it's marked by %RATINGS_IMAGES%. Any way to get that from the plugin?

(I can, of course, just use get_most_rated(); and modify the template to my needs, but then I won't be able to use stuff like tags and custom fields on my "top list" page).

Edit: OK, something like this will make the stars static. the_ratings_results gives static stars, and the_ratings_vote gives the voting ones. I still can't figure out how to get rid of the text.


--- Code: ---function the_ratings_static($start_tag = 'div') {
global $id;
$ratings_id = $id;
echo "<$start_tag id=\"post-ratings-$ratings_id\" class=\"post-ratings\">".the_ratings_results($ratings_id).'</'.$start_tag.'>';
return;
}
--- End code ---

infomancer:
I managed to do it, but in an extremely roundabout way. I know very little PHP so I can hardly recommend this ugly solution. However, if anyone's interested, here it is:

1. Add the following two functions:


--- Code: ---function the_ratings_static($start_tag = 'div') {
global $id;
$ratings_id = $id;
echo "<$start_tag id=\"post-ratings-$ratings_id\" class=\"post-ratings\">".the_ratings_results1($ratings_id).'</'.$start_tag.'>';
return;
}

function the_ratings_results1($post_id, $new_user = 0, $new_score = 0, $new_average = 0, $type = 0) {
if($new_user == 0 && $new_score == 0 && $new_average == 0) {
$post_ratings_data = null;
} else {
$post_ratings_data->ratings_users = $new_user;
$post_ratings_data->ratings_score = $new_score;
$post_ratings_data->ratings_average = $new_average;
}
$template_postratings_text = stripslashes(get_option('postratings_template_mostrated'));
return expand_ratings_template($template_postratings_text, $post_id, $post_ratings_data);
}
--- End code ---

2. Modify the "most rated" template to include only static stars (use %RATINGS_IMAGES%)

3. Call the_ratings_static function from your theme where you want to use it, like a boss!

harrisandreson:
Thank you for posting this fix (#1). One issue I ran into with it though. You have:
<?php
      $ip_address = $_SERVER['REMOTE_ADDR'];
?>
In order to work on sites that are running reverse proxies or load balancers it needs to be:
<?php
       $ip_address = ip_address();
?>

Once I made that change it worked perfectly for me.

Navigation

[0] Message Index

Go to full version