wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema
wp_star_rating › WordPress Function
Desde3.8.0
Obsoleton/a
› wp_star_rating ( $args = array() )
Parâmetros: |
|
Retorna: |
|
Definido em: |
|
Codex: | |
Log de mudanças: |
|
Output a HTML element with a star rating for a given rating.
Outputs a HTML element with the star rating exposed on a 0..5 scale in half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the number of ratings may also be displayed by passing the $number parameter.
Funções relacionadas: wp_user_settings, wp_installing, wp_set_all_user_settings, wp_list_cats, wp_stream_image
Fonte
function wp_star_rating( $args = array() ) { $defaults = array( 'rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true, ); $r = wp_parse_args( $args, $defaults ); // Non-English decimal places when the $rating is coming from a string $rating = (float) str_replace( ',', '.', $r['rating'] ); // Convert Percentage to star rating, 0..5 in .5 increments if ( 'percent' === $r['type'] ) { $rating = round( $rating / 10, 0 ) / 2; } // Calculate the number of each type of star needed $full_stars = floor( $rating ); $half_stars = ceil( $rating - $full_stars ); $empty_stars = 5 - $full_stars - $half_stars; if ( $r['number'] ) { /* translators: 1: the rating, 2: the number of ratings */ $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] ); $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) ); } else { /* translators: %s: the rating */ $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) ); } $output = '<div class="star-rating">'; $output .= '<span class="screen-reader-text">' . $title . '</span>'; $output .= str_repeat( '<div class="star star-full" aria-hidden="true"></div>', $full_stars ); $output .= str_repeat( '<div class="star star-half" aria-hidden="true"></div>', $half_stars ); $output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars ); $output .= '</div>'; if ( $r['echo'] ) { echo $output; } return $output; }