במערכת שאני מפתח כעת, התבקשתי לספק רכיב הצבעה על תוכן, ובכל פריט תוכן את התצוגה הבאה: כמה הצביעו בעד וכמה הצביעו נגד.
רכיב vote up / down, להורדה כאן
סיפק בדיוק את הפונקציונליות - אך תצוגת ברירת המחדל הינה סכום כל ההצבעות.
הפונקצייה הבאה שינתה את תצוגת ההצבעות מסכום כל ההצבעות לכמה הצביעו בעד וכמה נגד (למקם ב- template.php של התבנית שלכם)
<?php
function phptemplate_vote_up_down_points($cid, $type, $tag = NULL, $nodelink = FALSE) {
$tag = $tag ? $tag : variable_get('vote_up_down_tag', 'vote');
$criteria = array('content_type' => $type, 'content_id' => $cid, 'value_type' => 'points', 'tag' => $tag //, 'function' => 'sum'
);
$votes = votingapi_select_votes($criteria);
$items = array();
$results_upvote = $results_downvote = 0;
foreach ($votes as $vote) {
if ($vote['value']>0) $results_upvote += $vote['value'];
elseif ($vote['value']<0) $results_downvote += $vote['value'];
}
$items[] = array('class'=>'upvote','data'=>'<strong>'. $results_upvote .'</strong> <span>'.t('up').'</span>');
$items[] = array('class'=>'downvote','data'=>'<strong>'. $results_downvote .'</strong> <span>'.t('down').'</span>');
if ($nodelink) {
foreach($items as $item) $title .= '<span class="'.$item['class'].'">'.$item['data'].'</span>';
$output = array(
'title' => $title,
'html' => TRUE
);
}
else {
$output = theme('item_list',$items,null,'ul',array('id'=>'vote_points_'. $cid,'class'=>'vote-points'));
}
return $output;
}
?>