Review plugin for wordpress?

Question

I was searching for a simple plugin in order to display a rating system on one of my custom post type. As my CPT was already built, with filters and ajax load more, taxonomies and custom style, I didn’t wanted one of these complex plugin offering lots of options.

And finally i saw that there was a built in function

 wp_star_rating()

in the core of wordpress !! Fantastic !!

Finally it was quite simple

I have a custom post type called “review”. I needed to display in three rows three different reviews scores.
For example :

My CPost title

review 1 :….

review 2: ….

review 3: ….

the customer text…etc..

As I’m using ACF, I added three news custom fields for my custom post type.
Then, i followed the codex instruction.
In function.php, i added

 require_once( ABSPATH . 'wp-admin/includes/template.php' );

in my style.css file, i added

            @font-face {
                font-family: "dashicons";
                src: url("../fonts/dashicons.eot");
            }

            @font-face {
                font-family: "dashicons";
                src: url(data:application/x-font-woff;charset=utf-8;base64,/* !! Large amount of data removed, see wp-includes/css/dashicons.css for complete data !! */) format("woff"),
                    url("../fonts/dashicons.ttf") format("truetype"),
                    url("../fonts/dashicons.svg#dashicons") format("svg");
                font-weight: normal;
                font-style: normal;
            }

            .star-rating .star-full:before {
                content: "f155";
            }

            .star-rating .star-half:before {
                content: "f459";
            }

            .star-rating .star-empty:before {
                content: "f154";
            }

            .star-rating .star {
                color: #0074A2;
                display: inline-block;
                font-family: dashicons;
                font-size: 20px;
                font-style: normal;
                font-weight: 400;
                height: 20px;
                line-height: 1;
                text-align: center;
                text-decoration: inherit;
                vertical-align: top;
                width: 20px;
            }

Then in my custom post type, I directly inserted the custom fields values in the wp_star_rating arguments.

$animation = get_field('animation');
                            if($animation):
                             $args = array(
                               'rating' => $animation,
                               'type' => 'rating',
                               'number' => '',
                            );?>

                            <div>Animation: <?php  wp_star_rating( $args )?></div>;
                            <?php endif;?>

                            <?php 
                            $contenu = get_field('contenu');
                            if($contenu):
                             $args = array(
                               'rating' => $contenu,
                               'type' => 'rating',
                               'number' => '',
                            );?>

                            <div>Contenu: <?php  wp_star_rating( $args )?></div>;
                            <?php endif;?>

                            <?php 
                            $organisation = get_field('organisation');
                             if($organisation):
                             $args = array(
                               'rating' => $organisation,
                               'type' => 'rating',
                               'number' => '',
                            );?>

                            <div>Organisation: <?php  wp_star_rating( $args )?></div>;
                            <?php endif;?>
0
, , blogob 4 years 2020-03-25T16:52:19-05:00 0 Answers 114 views 0

Leave an answer

Browse
Browse