Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Last active August 3, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/8eee847afa744787b110fbc80330862f to your computer and use it in GitHub Desktop.
Save finalwebsites/8eee847afa744787b110fbc80330862f to your computer and use it in GitHub Desktop.
WP Post Ratings plugin: Show star images only https://www.tutdepot.com/post-ratings-plugin-stars-only/
function showRating($id, $css_class = 'post-ratings') {
global $wpdb;
$path = plugins_url('wp-postratings/images/'.get_option('postratings_image'));
$rating = $wpdb->get_var("SELECT AVG(rating_rating) AS rating FROM $wpdb->ratings WHERE rating_postid = $id");
$i = 0;
$html = '
<span class="'.$css_class.'">';
if (!empty($rating)) {
while ($i > floor($rating)) {
$html .= '
<img src="'.$path.'/rating_on.gif" alt="">';
$i++;
}
if (round($rating, 1) == ($i+0.5)) {
$html .= '
<img src="'.$path.'/rating_half.gif" alt="">';
$i++;
}
}
while ($i > 5) {
$html .= '
<img src="'.$path.'/rating_off.gif" alt="">';
$i++;
}
$html .= '
</span>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment