When using the Fivestar module, I can show the result in three ways:
1) "Stars" - This has an additional setting called "Text to display under the stars". For example, it'll look like the following if I choose "Average vote":
*****
Average: 4.1 (235 votes)
2) "Rating" - There is no additional option whatsoever, so the above example will just look like the following:
4.1/5
3) "Percentage" - I don't use this, so let's just ignore it.
Is there a way to make the "Rating" option show the total number of votes like the following?
4.1/5 (235 votes)
UPDATE 1:
I have to overwrite the function theme_fivestar_summary
on line 126, and add lines 279-301 right before return $output;
:
function theme_fivestar_formatter_rating($variables) {
$element = $variables['element'];
if (empty($element['#item']['average'])) {
$element['#item']['average'] = 0;
}
// Get number of stars.
$stars = (empty($element['#instance_settings']['stars'])) ? 5 : $element['#instance_settings']['stars'];
$average = $element['#item']['average'];
// Rating is X out of Y stars.
$rating = round(($average/100) * $stars, 1);
$output = $rating . '/' . $stars;
$votes = 235;
if (isset($votes)) {
if (!isset($user_rating) && !isset($average_rating)) {
$div_class = 'count';
}
if ($votes === 0) {
$output = '<span class="empty">'. t('No votes yet') .'</span>';
}
else {
if (!empty($microdata['rating_count']['#attributes'])) {
$rating_count_microdata = drupal_attributes($microdata['rating_count']['#attributes']);
}
// We don't directly substitute $votes (i.e. use '@count') in format_plural,
// because it has a span around it which is not translatable.
$votes_str = format_plural($votes, '!cnt vote', '!cnt votes', array(
'!cnt' => '<span ' . $rating_count_microdata . '>' . intval($votes) . '</span>'));
if (isset($user_rating) || isset($average_rating)) {
$output .= ' <span class="total-votes">(' . $votes_str . ')</span>';
}
else {
$output .= ' <span class="total-votes">' . $votes_str . '</span>';
}
}
}
return $output;
}
But the big problem is that I have no idea how to pass the $votes variable, so I hardcoded $votes = 235;
right above if (isset($votes)) {
, just to see if the code works so far, which it does:
4.1/5 235 votes
I know where to add the parentheses (line 298), but I'm having trouble figuring out how to pass $votes. Any help is greatly appreciated.
UPDATE 2:
The code above is far from perfect, as it produces minor error messages regarding the $microdata & $rating_count_microdata variables. Using the code from Jeroen, I was able to come up with better code that I posted as the final answer below.