Community

Programically Pull Average From 5 star. (schema.org compliance)

Working to try and get some Google Rich Snippets with the pretty little stars above an article in the SERP. We are working with drupal 6x which does not have a microdata module so we are trying to find a work around for this issue.

What we have is the five star module enabled on the "page" content type basic defaults.

The code we have come up with so far for rich snippets is:

<div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<meta itemprop="worstRating" content="1">
<meta itemprop="ratingValue" content="<?php $rating = $node->field_rating[0]['rating']; print $rating / 20; ?>">
<meta itemprop="bestRating" content="5">
</div>

Which would be fine if we were using axis and had a "review" page utilizing five star as a cck field. But we are just using the default enable on a content type.

Which Google recognizes if we were to just replace "<?php $rating = $node->field_rating[0]['rating']; print $rating / 20; ?>"> with the numeric value "5"; however that wouldn't exactly be truthful and as quickly as google changes algorithms and looks for cheaters would probably get us in trouble at some point.

So what do we replace:"<?php $rating = $node->field_rating[0]['rating']; print $rating / 20; ?>">with and insert into page.tpl.php to programmicaly grab just the average and not the form or anything else..

The end result when viewing page source would be:

<div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<meta itemprop="worstRating" content="1">
<meta itemprop="ratingValue" content="five star average 1-5">
<meta itemprop="bestRating" content="5">

Comments

I also found another <div

I also found another

<div class="left" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
<meta itemprop="ratingValue" content="3.45" />
<meta itemprop="ratingCount" content="38" />
<h4>Ratings</h4> <div class="star-holder">
<div class="star-rating" style="width: 63.48px">3 stars</div>
</div>
<span>3.5 out of 5 stars</span>

But again I have know idea how to programically fill in the variables

Figured it out..

It took about a day to figure out but it works perfectly now and prints the specific portions of microdata I needed for my drupal 6.0 site with five star module to comply with http://schema.org.
The end result is this:

<div itemprop="reviewRating" itemscope itemtype="http://schema.org/AggregateRating">
<meta itemprop="worstRating" content="1">
<meta itemprop="ratingValue" content="4.5">
<meta itemprop="bestRating" content="5">
<meta itemprop="ratingCount" content="2">

in every page with the five star widget. I checked it with the google rich snippet tool and now I have those little stars, a rating and a vote count in the SERP. Basically the code I entered into my tpl.php pulls either the average or the vote count directly from five star and prints them in the appropriate "itemprop" field above.