K2_content module rating

扶醉桌前 提交于 2019-12-23 17:24:35

问题


I've been reconstructing the standard K2 rating in the category_item.php to view ratings from to show as stars to show as number.

What I did was, I replaced this code:

<?php if($this->item->params->get('catItemRating')): ?>
<div id="catItemRatingBlock">
 <div class="itemRatingForm">
  <ul class="itemRatingList">
    <li class="itemCurrentRating" id="itemCurrentRating<?php echo $this->item->id; ?>" style="width:<?php echo $this->item->votingPercentage; ?>%;"></li>
    <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="one-star">1</a></li>
    <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="two-stars">2</a></li>
    <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="three-stars">3</a></li>
    <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="four-stars">4</a></li>
    <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="five-stars">5</a></li>
   </ul>
  </div>
  </div>
 <?php endif; ?>

with this code:

<?php if($this->item->params->get('catItemRating')): ?>
<div id="catItemRatingBlock">
<div class="itemRatingForm">
   <?php
   $rating_sum=0;
   $rating_cont=0;
   $db        =& JFactory::getDBO();
   $query='SELECT * FROM #__k2_rating WHERE itemID='. $this->item->id;
   $db->setQuery($query);
   $votes=$db->loadObject();

   $rating_sum = intval($votes->rating_sum);
   $rating_count = intval($votes->rating_count);
   $evaluate = ($rating_count==0) ? "0" : number_format($rating_sum/$rating_count,1);

   $evaluate = str_replace('.0', '', $evaluate);

   $output=" Rating: ". $evaluate."/5";
   echo $output;
   ?>
   </div>
   </div>
   <?php endif; ?>

And what I want is for it to work on the K2 module as well. I tried to use the same code that I wrote above here to achieve it in k2 content module but that doesn't work at all.

Anyone know how to pull it off?


回答1:


Replace

<?php if($this->item->params->get('catItemRating')): ?>

with:

<?php if($params->get('catItemRating')): ?>


来源:https://stackoverflow.com/questions/12134185/k2-content-module-rating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!