• Hi,

    i would edit our single recipe template like the amazon platform for the ratings. In the teaser you see all the ratings in average with stars. After clicking on the link, you will jump on the comment form / rating form. Now you can rate the recipe.

    So you can see: I want only the images of the rating in average in the teaser. Below on the site the real rating form, also with stars, now with the click event.

    Is this possible? I hope so!

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • put this in functions.php

    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;			
    }

    and with this call it in your theme

    echo showRating(get_the_ID());

Viewing 1 replies (of 1 total)
  • The topic ‘Show only results in images (without onclick event)’ is closed to new replies.