All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.

Author Topic: Display only stars (no text, no votes allowed)  (Read 3161 times)

0 Members and 1 Guest are viewing this topic.

Offline infomancer

  • Newbie
  • *
  • Posts: 4
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: Grey
Display only stars (no text, no votes allowed)
« on: 06 September 2011, 19:18 »
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: [Select]
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;
}
« Last Edit: 06 September 2011, 20:17 by infomancer »

Offline infomancer

  • Newbie
  • *
  • Posts: 4
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: Grey
Re: Display only stars (no text, no votes allowed)
« Reply #1 on: 09 September 2011, 23:42 »
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: [Select]
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);
}

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!

Offline harrisandreson

  • Newbie
  • *
  • Posts: 2
    • View Profile
  • WordPress Version: WordPress 2.8.x
  • Theme Name: Arjuna X
Re: Display only stars (no text, no votes allowed)
« Reply #2 on: 22 June 2012, 20:21 »
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.
« Last Edit: 27 June 2012, 01:48 by GaMerZ »
Memories reminds the past beauty, protect your dreams, Truly Sincere USA