Evgeniy
Evgeniy

Reputation: 2605

Getting K2 extra fields and rating into the search results, generic.php

I try to show tags, item rating and exztra fields in the search results. I got tags to show, but i fail with rating and extra fields. Can somebody advice me or give a code example? Here is the code to show tags in 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; ?>

Thanks in advance for your help! regards chillyB

Upvotes: 2

Views: 961

Answers (1)

Royce H
Royce H

Reputation: 51

This worked for me:

$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>

Upvotes: 1

Related Questions