Keyword

mod_k2_content show rating star system for articles

  • Brett Johnson
  • Brett Johnson's Avatar Topic Author
  • Offline
  • New Member
More
13 years 7 months ago #94317 by Brett Johnson
Hello everyone, I'm using mod_k2_content on the homepage of my site to display articles.  I want to show the article star rating system in the module to the right of where it says the number of hits.

 

I'm wondering if anyone knows what code I would insert into the modules/mod_k2_content/tmpl/Default/default.php file

 

I found the article rating code below in the components/com_k2/default/item.php file and played around with it a little but couldn't get the rating to match up with the articles rating.

 

<?php if($this->item->params->get('itemRating')): ?>    <!-- Item Rating -->    <div class="itemRatingBlock">        <span><?php echo JText::_('Rate this item'); ?></span>        <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; ?>" title="<?php echo JText::_('1 star out of 5'); ?>" class="one-star">1</a></li>                <li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('2 stars out of 5'); ?>" class="two-stars">2</a></li>                <li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('3 stars out of 5'); ?>" class="three-stars">3</a></li>                <li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('4 stars out of 5'); ?>" class="four-stars">4</a></li>                <li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('5 stars out of 5'); ?>" class="five-stars">5</a></li>            </ul>            <div id="itemRatingLog<?php echo $this->item->id; ?>" class="itemRatingLog"><?php echo $this->item->numOfvotes; ?></div>            <div class="clr"></div>        </div>        <div class="clr"></div>    </div>    <?php endif; ?><br>

 

 

If anyone has done this before any could provide the coding that would be great.  I think putting it on the homepage it cant find the itemid to retrieve the rating from but that's just a guess.

 

thanks,

brett

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

More
13 years 7 months ago #94318 by marioglez
I am interested in this as well!

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

  • Brett Johnson
  • Brett Johnson's Avatar Topic Author
  • Offline
  • New Member
More
13 years 7 months ago #94319 by Brett Johnson
Replied by Brett Johnson on topic mod_k2_content show rating star system for articles
If anyone can figure out the code to paste in by 02/23/2011 I'll paypal them $10

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

  • Brett Johnson
  • Brett Johnson's Avatar Topic Author
  • Offline
  • New Member
More
13 years 6 months ago #94320 by Brett Johnson
Replied by Brett Johnson on topic mod_k2_content show rating star system for articles
anyone know a paid service to get help with k2?

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

More
13 years 5 months ago #94321 by BBC
New AidaNews has Beta module:

code.google.com/p/aidanews/downloads/detail?name=mod_aidanews_for_K2_2_beta2.zip

 

It shows all stars (no rating possibility). Try it and see if you will be satisfied how stars look.

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

More
13 years 5 months ago #94322 by BBC
You can cut a yellow star from K2 stars css sprite image, and replace yellow star in module.

Just cut it to the same size in pixels.

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

More
13 years 5 months ago #94323 by BBC
It is a only workaround without code tweak. Not so perfect because it doesn´t show values between stars (value with yellow star a half, or different populated), only one star.

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

More
13 years 5 months ago #94324 by Marius
If you want to retrieve only count of votes, you have to add the following PHP code:

$query = 'SELECT rating_count FROM #__k2_rating WHERE itemID = ' . $item->id;

$db->setQuery($query);

$item->votes=$db->loadResult();


insert this code into modules/mod_k2_content/helper.php, straight after foreach($items as $item){ statement, somewhere at line 220. Then all you have to do in your template file of k2_content is:

<?php echo $item->votes; ?>

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

  • Brett Johnson
  • Brett Johnson's Avatar Topic Author
  • Offline
  • New Member
More
12 years 11 months ago #94325 by Brett Johnson
Replied by Brett Johnson on topic mod_k2_content show rating star system for articles
that code works marius, but doesnt really help unless it can be somehow tied in with the stars, anyone have any ideas on what to change in the code or add? The stars show up with the code, but are all white and nothing happens when you try to rate it

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


Powered by Kunena Forum