我正在使用带投票轴的 Fivestar 1.19。我相信默认的五星级块/五星级功能仅使用默认的“投票”标签。
Fivestar_widget_form($node)
我需要将我的自定义五星级标签传递给函数。
尝试遵循以下答案:对我来说 $object 是 $node。
<?php
function custom_fivestar_widget ($object) {
global $user;
$star_display = variable_get('fivestar_style_'. $object->type, 'average');
$text_display = variable_get('fivestar_text_'. $object->type, 'dual');
if ($star_display == 'average' && ($text_display == 'average' || $text_display == 'none')) {
// Save a query and don't retrieve the user vote unnecessarily.
$votes = fivestar_get_votes($object->type, $object->nid, 'score', 0);
}
else {
$votes = fivestar_get_votes($object->type, $object->nid);
}
$values = array(
'user' => isset($votes['user']['value']) ? $votes['user']['value'] : 0,
'average' => isset($votes['average']['value']) ? $votes['average']['value'] : 0,
'count' => isset($votes['count']['value']) ? $votes['count']['value'] : 0,
);
$settings = array(
'stars' => variable_get('fivestar_stars_'. $object->type, 10),
'allow_clear' => variable_get('fivestar_unvote_'. $object->type, FALSE),
'style' => $star_display,
'text' => $text_display,
'content_type' => $object->type,
'content_id' => $object->nid,
'tag' => 'score',
'autosubmit' => TRUE,
'title' => variable_get('fivestar_title_'. $object->type, 1) ? NULL : FALSE,
'feedback_enable' => variable_get('fivestar_feedback_'. $object->type, 1),
'labels_enable' => variable_get('fivestar_labels_enable_'. $object->type, 1),
'labels' => variable_get('fivestar_labels_'. $object->type, array()),
);
return fivestar_custom_widget($form_state, $values, $settings);
}
print drupal_get_form('custom_fivestar_widget', $object);
?>
这会打印我的小部件,我相信使用我的分数。但是文本显示都是错误的,平均分数也是如此。它给所有东西一个永久的 10 颗星。:(