Keyword

How to show item ratings in the K2 Content Module?

  • arien101
  • arien101's Avatar Topic Author
  • Offline
  • New Member
More
12 years 4 months ago #60143 by arien101
Hi,

I use a K2 Content Module to display a list of items sorted by their rating on the homepage. So far so good.

Now I would like to display the current rating next to each item in the list.

I have figured out that the .php file I need to edit is default.php in the mod_k2_module directory. I have copied over the itemRating code from category_item.php, but that only shows grey stars and not the item rating.

I figure this might be because
<?php echo $this->item->id; ?>
only works on the page of the item. Unfortunately I lack the PHP skills to figure out how to change this.

Any idea what code I would need?

Thanks!

Please Log in or Create an account to join the conversation.

More
12 years 4 months ago #60144 by DJ Enterprises
Replied by DJ Enterprises on topic Re: How to show item ratings in the K2 Content Module?
Anyone?

I would like to know about the Ratings as well

Seems as if it was overlooked in development

Thank you for your time

Please Log in or Create an account to join the conversation.

More
12 years 1 week ago #60145 by Kit
I, too, would like to know how to do this.

Anyone have an answer?

Thanks in advance...

Please Log in or Create an account to join the conversation.

  • Andrey Miasoedov
  • Andrey Miasoedov's Avatar
  • Offline
  • Senior Member
More
12 years 1 week ago #60146 by Andrey Miasoedov
Replied by Andrey Miasoedov on topic Re: How to show item ratings in the K2 Content Module?
Hello, all.

You need to do the following, for showing item rating in mod_k2_content:

1) In helper.php before $rows[] = $item; at line 569 add the following:
$item->votingPercentage = $model->getVotesPercentage($item->id);
$item->numOfvotes = $model->getVotesNum($item->id);

2) Copy rating block from item.php template (or category_item.php) to any place in default.php of mod_k2_content;

3) Change all "$this->item" to "$item" in rating block text.

Please Log in or Create an account to join the conversation.

More
12 years 1 week ago - 12 years 1 week ago #60147 by Kit
Andrey, you ROCK!! :woohoo:

That got me EXACTLY where I needed to be.

Small fyis to anyone else who happens to come along after this with the same issue, if they need it:
1. the helper.php is at: modules -> mod_k2_content -> helper.php

2. the item.php template (or category_item.php) are in: components -> com_k2 -> templates -> default -> item.php template (or category_item.php)

3. don't copy the php code on top or bottom of the <!-- Item Rating --> section

4. If you leave the code as it is, people will still be able to vote. To JUST show the star rating and NOT have people vote, take out:

replace this:
		
Attachments:

Please Log in or Create an account to join the conversation.

More
11 years 4 months ago #60148 by Adam
Hi
I have one more question. Is it possible to get a result like on the image "siteissue.jpg " without clicking the mouse on the stars?

Please Log in or Create an account to join the conversation.

More
10 years 11 months ago #60149 by jeyjoo
Nice - thanks Andrey

Please Log in or Create an account to join the conversation.

More
10 years 11 months ago #60150 by Jr Tony Gvr
i have a problem here :( star show in last item :( not look like the demo you do , what should i do now :(
<div class="catItemRatingBlock">
		
		<div class="itemRatingForm">
			<ul class="itemRatingList">
				<li class="itemCurrentRating" id="itemCurrentRating<?php echo $item->id; ?>" style="width:<?php echo $item->votingPercentage; ?>%;"></li>
				
			</ul>
			<div id="itemRatingLog<?php echo $item->id; ?>" class="itemRatingLog"><?php echo $item->numOfvotes; ?></div>
			<div class="clr"></div>
		</div>
		<div class="clr"></div>
	</div>
here is my code in default.php


hope to see your answer soon

Please Log in or Create an account to join the conversation.

More
10 years 11 months ago #60151 by Jr Tony Gvr
Small tip to anyone else who happens to come along after this with the same issue, and you don't know all of solution of andrey and kit explain .......


you copy the code like previous comment of me and copy in module/mod_k2_content/tmpl/default/default.php in line 39 you will see
<?php if($params->get('itemTitle')): ?>
      <a class="moduleItemTitle" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a>
      <?php endif; ?>
, paste my code in previous comment after this line , and check the result , if you want display a star in another position , u can paste in every you want in default template of module k2 content

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago #60152 by Alessandro
Hello!
To show rating stars in News Show Pro GK5 use these variables:
<li class="itemCurrentRating" id="itemCurrentRating" style="width:'. number_format(($item['rating_sum'] / $item['rating_count'])/5*100,0) . '%;"></li>

:)

Please Log in or Create an account to join the conversation.