400行目くらいから class-shortcode.php
id raty_rich だからループでおかしくなってたので
クラスにかえ、更に、
記事IDを入れたクラスを付け そこに 星を入れる設定にした。
$query = new WP_Query( $query_args ); $total_rating = 0; if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); $total_rating += intval( get_post_meta( $post->ID ,'wpbr_review_rating',true ) ); $parent_title = get_the_title( wp_get_post_parent_id( $post->ID ) ); //tuiki $d_id = $post->ID; endwhile; $rich_rating = "<div class='raty_rich raty_rich".$d_id."' style='color:". review_get_option( 'rating_icon_color', 'wpbr_display' ) ."'></div>"; if ( 'star' === review_get_option( 'review_icon', 'wpbr_display' ) ) { $rich_rating .= "<script> jQuery('.raty_rich".$d_id."').raty({ readOnly : true, cancel : false, half : true, score : '".round( $total_rating / $query->post_count , 2 )."', starType : 'i', starHalf : 'wpbr-star-half', starOff : 'wpbr-star-off', starOn : 'wpbr-star-on', }); </script>"; } else { $rich_rating .= "<script> jQuery('.raty_rich').raty({ readOnly : true, cancel : false, half : true, score : '".round( $total_rating / $query->post_count , 2 )."', starType : 'i', starHalf : 'wpbr-heart-half', starOff : 'wpbr-heart-off', starOn : 'wpbr-heart-on', }); </script>"; } ob_start(); ?> <!--シングル--> <?php if(is_single()):?> <div itemscope itemtype="http://schema.org/Product" class="d_rate"> <span itemprop="name" style="display:none"><?php echo esc_html( $parent_title ); ?></span> <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating" > <div class="d_rate2">5つ星のうち<span itemprop="ratingValue"><?php echo esc_html( round( $total_rating / $query->post_count , 2 ) ); ?></span> </div> <!-- based on--> <div class="link_color d_rate3" style="cursor: pointer"> <span itemprop="reviewCount"><?php echo esc_html( $query->post_count ); ?></span>件のレビュー</div> <div style="display:none"> <span itemprop="bestRating">5</span> <span itemprop="worstRating">1</span> </div> </div> </div> <?php else:?> <!--ループ--> <div itemscope itemtype="http://schema.org/Product" class="d_rate" style="margin-left: -12px;"> <span itemprop="name" style="display:none"><?php echo esc_html( $parent_title ); ?></span> <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating" > <div class="d_rate2">5つ星のうち<span itemprop="ratingValue"><?php echo esc_html( round( $total_rating / $query->post_count , 2 ) ); ?></span> </div> <!-- based on--> <div class=" d_rate3">(<span itemprop="reviewCount"><?php echo esc_html( $query->post_count ); ?></span>件)</div> <div style="display:none"> <span itemprop="bestRating">5</span> <span itemprop="worstRating">1</span> </div> </div> </div> <?php endif;?> <?php $rich_rating .= ob_get_clean(); return $rich_rating; endif; wp_reset_postdata();