我尝试在搜索结果中显示代码,商品评分和exztra字段。我有标签显示,但我失败了评级和额外的字段。有人可以建议我或给出一个代码示例吗? 以下是在generic.php中显示标记的代码:
<?php
$tags = K2ModelItem::getItemTags($item->id);
for ($i=0; $i<sizeof($tags); $i++) {
$tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
}
$item->tags=$tags;
?>
<?php if(count($item->tags)): ?>
<!-- Item tags -->
<div class="genericItemTagsBlock">
<span><?php echo JText::_("Tagged under"); ?></span>
<ul class="genericItemTags">
<?php foreach ($item->tags as $tag): ?>
<li><a href="<?php echo $tag->link; ?>"><?php echo $tag->name; ?></a></li>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
提前感谢您的帮助! 问候 chillyB
答案 0 :(得分:1)
这对我有用:
$rating_width = 0;
$vote = K2ModelItem::getRating($item->id);
if (!is_null($vote) && $vote->rating_count != 0) {
$rating_width = number_format(intval($vote->rating_sum) / intval($vote->rating_count), 2) * 20;
}
<div class="itemRatingBlock">
<div class="itemRatingForm">
<ul class="itemRatingList">
<li class="itemCurrentRating" id="itemCurrentRating<?php echo $item->id; ?>" style="cursor: inherit; width:<?php echo $rating_width;?>%;">
</li>
</ul>
</div>