According to the guide, to add average rating:
Add the following function anywhere on this file:
HTML Code:
function get_average_rating() {
global $post;
$this->get_aggregate_reviews($post->ID);
$average_score = number_format($this->got_aggregate["aggregate"], 1);
return $average_score * 20; // 20% for each star if having 5 stars
}
Then inside the function do_the_content($original_content), just after $the_content = ''; add the following:
HTML Code:
// build average ratings html
$average_rating = 'Average Rating: <div class="sp_rating"><div class="base"><div class="average" style="width:'.$this->get_average_rating().'%"></div></div></div>';
Then find the following line:
$the_content .= '<div id="wpcr_respond_1">'; /* start the div */
and place the following just below it:
HTML Code:
// attach average ratings to beginning of reviews
$the_content .= $average_rating;
I follow the guide and it work, but the position is above the reviews, not byline position as I want.
I Edited
bfa_post_parts.php and added:
HTML Code:
// build average ratings html
$average_rating = 'Average Rating: <div class="sp_rating"><div class="base"><div class="average" style="width:'.$this->get_average_rating().'%"></div></div></div>';
Then find the following line:
$the_content .= '<div id="wpcr_respond_1">'; /* start the div */
Inside "byline", I added:
HTML Code:
// build average ratings html
$average_rating = 'Average Rating: <div class="sp_rating"><div class="base"><div class="average" style="width:'.$this->get_average_rating().'%"></div></div></div>';
// attach average ratings to beginning of reviews
$the_content .= $average_rating;
But error:
Fatal error: Using $this when not in object context in /home/digital1/public_html/wp-content/themes/atahualpa/functions/bfa_post_parts.php on line 102
Could you please explain what's wrong with the code that I added.
Thank you