Sample PHP code (calling the API):
<?php //That's your shortname $shortname = "demo"; //Dynamic parameters for product information, please fill all the fields $sku = "pop"; //Feel free to add some caching at this place $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://" . $shortname . ".reziew.com/api/1/review/average.json?sku=$sku"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); //This is important to leave at most a 1 second timeout - otherwise your page will be blocked until the API respons curl_setopt($ch, CURLOPT_TIMEOUT, 1); //Post all the params to the api $data = curl_exec($ch); $dataObj = (json_decode($data)); if(count($dataObj)){ $average_rating = $dataObj->$sku->average; $review_count = $dataObj->$sku->count; echo "Count: ". $review_count; echo "<br>"; echo "Average: ". $average_rating; } else { echo "No rating"; } ?>
Sample HTML code:
Here it’s important that you follow the HTML structure, this is a standard format (microdata). More documentation can be found here: http://schema.org/AggregateRating. The CSS provided is just an example feel free to use your own.<link rel="text/css" src="http://media.reziew.com/css/rating-element.css"/> <div class="title" itemscope="" itemtype="http://data-vocabulary.org/Review-aggregate"> <h1 itemprop="itemreviewed"> %YOUR_PRODUCT_TITLE% </h1> <div class="read-only-rating grade-40 small-star" itemprop="rating" itemscope="" itemtype="http://data-vocabulary.org/Rating"> <span class="average" itemprop="average"> %AVERAGE_RATING% </span> <span class="slashReview"> / </span> <span class="best" itemprop="best"> 5 </span> <br> Based On <a class="linkToReviews"> <span itemprop="votes"> %REVIEW_COUNT% </span> Reviews </a> </div> </div>