- Posts: 157
COMMUNITY FORUM
K2 Rating on Google
- Goble002
-
Topic Author
- Offline
- Premium Member
I've searched a bit on the forum but the related posts are a bit old.
Running K2 2.7.1 with template override. Is there actually a plugin that can be used to get Rating Value for Google Mircrodata ?
Or else, is there already some specific codes out there which I can use ?
Thanks !
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
I read this post before. However some people reported having issues with their codes, I was wondering if you have one that works for sure.
P.S. Am not a PHP coder.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The complaints were that the reviews code should be used, instead.
The rating microdata is however correct.
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
am not sure what you meant by "the reviews code should be used'. Anyway I have used hereunder but errors with Google 'structured data testing tool' search.google.com/structured-data/testing-tool
<?php if($params->get('itemRating')): ?>
<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating" class="itemRatingBlock">
<span><?php echo JText::_('K2_RATE_THIS_ITEM'); ?></span>
<meta itemprop="worstRating" content="1">
<meta itemprop="bestRating" content="5">
<meta itemprop="ratingValue" content="<?php echo (($this->item->votingPercentage)/20);?>"/>
<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::_('K2_1_STAR_OUT_OF_5'); ?>" class="one-star">1</a> </li>
<li> <a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_2_STARS_OUT_OF_5'); ?>" class="two-stars">2</a> </li>
<li> <a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_3_STARS_OUT_OF_5'); ?>" class="three-stars">3</a> </li>
<li> <a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_4_STARS_OUT_OF_5'); ?>" class="four-stars">4</a> </li>
<li> <a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_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>
<meta itemprop="ratingCount" content="<?php echo (preg_replace('/[^0-9]/', '', $this->item->numOfvotes)); ?>"/>
</div>
</div>
<?php endif; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Have you posted the code in your site so I can take a look?
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
got error hereunder when I include them on my website:
Fatal error: Call to a member function get() on null in .../templates/my_template/html/com_k2/item/item.php on line 191
Line 191 starts with:
<?php if($params->get('itemRating')): ?>
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
any update on above ? Thanks !
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
any update on above ? Thanks !
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
desperately needing to include this in K2, anyone been able to make it work ? Any plugin that exists that would do the job ?
Thanks !
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The correct parameter statement should be:
<?php if($this->item->params->get('itemRating')): ?>
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
no errors now. However search.google.com/structured-data/testing-tool does not detect any structured data.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
The link: www.webs800.com/en/services/web-development/web-design-maintenance
I just noticed that I wrongly pasted the code last time which made me thought that were no more errors (sometimes errors seem to occur when you copy large amount of codes in template overrides).
Anyway with the code hereunder, it will just break the layout of my page. So I reverted back to the codes without microdata.
<?php if($this->item->params->get('itemRating')): ?>
<!-- Item Rating -->
<div class="itemRatingBlock">
<span><?php echo JText::_('K2_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="#" data-id="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_1_STAR_OUT_OF_5'); ?>" class="one-star">1</a></li>
<li><a href="#" data-id="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_2_STARS_OUT_OF_5'); ?>" class="two-stars">2</a></li>
<li><a href="#" data-id="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_3_STARS_OUT_OF_5'); ?>" class="three-stars">3</a></li>
<li><a href="#" data-id="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_4_STARS_OUT_OF_5'); ?>" class="four-stars">4</a></li>
<li><a href="#" data-id="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_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; ?>
With this code also Structured Data Testing Tool says: The review has no reviewed item specified.
So I have also tried with
<span itemprop="itemreviewed"><?php echo JText::_('K2_RATE_THIS_ITEM'); ?></span>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
There is an example here with more complete code, but only try the itemprop values not the PHP part.
github.com/kricore/Advanced-templating-with-K2/blob/master/default/item.php
Please Log in or Create an account to join the conversation.
- Goble002
-
Topic Author
- Offline
- Premium Member
- Posts: 157
like mentioned the code was breaking my layout so I had to remove it. I have made a copy of the website and use the code here:
www.webs800.com/webs801/en/services/web-development/web-design-maintenance
In the link you sent, there are no: itemprop="itemreviewed"
This is what is missing as per Google Structured Data Testing Tool
Thanks again for your help !
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
If the object is not defined, which in this case is the article, the rating code will not be picked up.
Please Log in or Create an account to join the conversation.