Rating block showing own rating only

Developer Knowledge Level

This content is intended for WordPress developers, and it may require coding knowledge of WordPress, PHP, and JavaScript. Code examples provided here may contain errors or needs some additional coding. Make sure to test the code before using it on a live website!

Templates for rating blocks are used to display ratings, and they can be customized to adjust how the ratings are displayed. Each rating methods has own set of templates, and they all use a similar way of doing things.

This tutorial will show how to show users own rating only so that users can’t see an overall rating for the item. This is a useful way to get the votes, but not use overall rating to influence voters.

Before we get on with this article, make sure to check this article with in-depth details about customization process.

To make sure that user can see only own votes, we need to modify stars display function, and to remove the rating text line because it shows average rating and a total number of votes. We are leaving the user rating text line because it is useful for the current user rating.

Before I explain how the template works, download the ZIP file attached with this tutorial and unpack the template into the active theme folder. Now, we need to let the plugin know about the new template. To do that, open plugin Tools panel, and open Recheck and Update. This will scan for the new template and will add a new ‘Default, With Own Rating’ template. Any time you add new templates, make sure to recheck again for the plugin to get the new template. You can now use this template from plugin settings.

A key part of this template is line 12:

gdrts_loop()->render()->stars(array('show_rating' => 'own'));

This is a simple change, that will change stars rendering to tell the plugin to show own rating for currently logged in user. After that, the block that shows a line of rating text is removed. Other parts of the default template remain.

So, with few minor changes, the new template will show rating for current user only, other users will not see average rating, and they can vote without being influenced by other users ratings.

2
0
787
Rate this article

You are not allowed to rate this post.

Leave a Comment