• Hi,
    On line 689 in the /kk-star-ratings/index.php file the if-statement needs to be moved to the beginning of the next function on line 704.

    This way the aggregaterating html code is not shown when there are no reviews. This html code is not visible anyway when there are no reviews, so nothing is lost. If not changed, Google will have issues with the ratingCount being set to zero (0). Apparantly this is not allowed by Google.

    For illustrative purposes:

            public function sanitize_legend($legend, $id, $best, $score, $votes, $avg, $per)
            {
    /* remove from here
                if(!$score)
                {
                    return parent::get_options('kksr_init_msg');
                }
    */
                $leg = str_replace('[total]', '<span itemprop="ratingCount">'.$votes.'</span>', $legend);
                $leg = str_replace('[avg]', '<span itemprop="ratingValue">'.$avg.'</span>', $leg);
                $leg = str_replace('[per]',  $per .'%', $leg);
                $leg = str_replace('[s]', $votes == 1 ? '' : 's', $leg);
                $leg = str_replace('[best]', $best, $leg);
    
                return $leg;
            }
            public function grs_legend($legend, $id, $best, $score, $votes, $avg, $per)
            {
    /* move it over here */
                if(!$score)
                {
                    return parent::get_options('kksr_init_msg');
                }
    /* --- */
                if(!parent::get_options('kksr_grs'))
                {
                    return $legend;
                }
    
                $title = get_the_title($id);
    
                $snippet = '<div itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">';
                $snippet .= '    <div itemprop="name" class="kksr-title">' . $title . '</div>';
                $snippet .=      $legend;
                $snippet .= '    <meta itemprop="bestRating" content="'. $best . '"/>';
                $snippet .= '    <meta itemprop="worstRating" content="1"/>';
                $snippet .= '    <div itemprop="itemReviewed" itemscope itemtype="https://schema.org/CreativeWork">';
                $snippet .= '    <!-- Product properties -->';
                $snippet .= '    </div>';
                $snippet .= '</div>';
    
                return $snippet;
            }
        }
    
    • This topic was modified 6 years, 11 months ago by janpaulkleijn.
  • The topic ‘The aggregaterating ratingcount cannot be zero’ is closed to new replies.