到目前为止,我已经设计了此功能,以便在每个评论下方的前端显示评级星:
add_filter( \'comment_text\', \'additional_fields\' );
function additional_fields ($below) {
global $comment;
if(!get_comment_meta( get_comment_ID(), \'rating\', true ) ) {
$ratsec = \'<form action="\'.get_permalink().\'" method="get" class="comment-form-rating">\';
$ratsec .= \'<div id="stars1">
<div class="option starr1">1</div>
<div class="option starr2">2</div>
<div class="option starr3">3</div>
<div class="option starr4">4</div>
<div class="option starr5">5</div>
</div>
<div style="clear:both"></div>\';
$ratsec .= \'<input type="hidden" name="p" value="\'.get_the_ID().\'"/>\';
$ratsec .= \'<input type="text" value="" name="rating[\'.$comment->comment_ID.\']" id="rate22" class="fruit-name"/>\';
$ratsec .= \'<label for="rating">\'. __(\'Rating\') . \'</label>\';
$ratsec .= \'<input type="submit" value="submit" />\';
$ratsec .= \'</form>\';
$below = $below .$ratsec;
return $below;
}
else
$ratsec = "";
$below = $below .$ratsec;
return $below;
}
并使用以下jQuery脚本:<script type="text/javascript">
(function($){
$(document).ready(function() {
var $option = $(\'.option\');
var $fruit = $(\'.fruit-name\');
var $last;
$option.click(function() {
$fruit.val(this.innerHTML)
})
});
})(jQuery);
</script>
现在,当我在其中添加一个悬停动作以使星形变黄时,它将使所有注释中的所有星形变黄,并且当我单击任何星形时,它的值将更新为注释下面的所有字段。我在这里想要的是让它为每个评论单独工作?比如,如果我为注释id 33按2星,它应该只更改注释id 33字段的颜色和值。并非所有评论。