Drupal 7 Fivestar Module

By shane
Fri, 2012-12-21 20:34
Daily Dose of Drupal Episode #73

Share with Others

The Drupal 7 Fivestar module can be used to easily rate various types of content on a Drupal 7 website. These ratings can be used on the content itself or even from the comments of that piece of content.

In this episode you will learn:

  • How to install and configure the Drupal 7 Fivestar module
  • How to create a simple Fivestar rating system on an article content type
  • How to create a comment based Fivestar rating system where the ratings are driven by the users leaving a comment and a rating at the same time

Hello there everyone and welcome to another Daily Dose of Drupal! Today we’re on Episode Number 73, as always I’m Shane, you can follow me on Twitter @smthomas3, you can also go to codekarate.com and check out the other Daily Dose of Drupal videos, enter to win the book contest if it’s still available and sign up for the newsletter.

Today we’re going to be going over module that I’ve used quite frequently on both Drupal 6 and Drupal 7 sites and that is the Five Star Module. What this module is going to allow us to do is set it up to rate content. Let’s say you have an article or you have a product and you want the ability to rate it based on a star system, maybe it’s five star or four stars, whatever number of stars you want, you can set up the module to work with you and to rate that content.

This module also requires the voting API so you’ll need to make sure you’ll get that installed as well and it has views integration which can be useful if you need to display of the highest rated items.

So that’s probably something you’re going to need something you’re going to want to look at. We’re not going to go over the Views Integration today; we’re going to go through two scenarios.

The first; you have an article that you want someone to just be able to read and rate without having to leave a comment. The second one is actually forcing the user to lea comment when they leave a rating and not allowing them to rate without leaving a comment.

So the first one is useful for articles as I mentioned before if you want someone to just quickly vote on something, the other one can be useful if you want them to leave a product review and leave a rating on a specific product.

So let’s go ahead and get started; we have a pretty much brand new test site here that I’m logged in to as the admin and I’ve already downloaded the modules for Five Star and Voting API and I’m just going to go ahead and turn those both on. I’m then going to come in and set the permissions for the Five Star module and you’ll notice that we’re going to give the ability to rate content to authenticated users and I’m going to save that.

And because I’m going to need a test user I’m going to go ahead and create a new user and give them a simple user account so I can test it and you can see I have two articles; the first thing we’re going to do is come to the configuration page on the Five Star Module and that’s going to allow us just to look at one quick thing; we don’t really need to worry about it too much but it basically allows you to set multiple voting tags.

You really need to use this if you’re going to have multiple ratings on one node or one piece of content, we only want one rating so we’re just going to leave the default vote, you could of course add multiple, just separate it with a comma. The next step is going to be adding the field to our content type.

This is a little different than the Drupal 6 version so if you use the Drupal 6 version in the past and haven’t use the Drupal 7 version, it has change a little bit, we’re going to go to Manage Fields on the article content type and we’re going to add a Five Star Rating field. We’re going to call this Article Rating and we’re going to set the stars rated while viewing.

So when they’re actually are viewing the node and not creating the node they can set the rating, we’ll save this, we’ll leave everything else at its default, I’m going to move this up so as a little .. I guess it doesn’t need to … it doesn’t matter but just a preference I guess I’m going to then go to Manage Display and here I’m also going to move this up above the body field and the format is going to be as stars, you could of course show it so it’s only going to give a numeric rating or a percentage rating, I’ll leave it a default but you want to click on this little settings I can over here.

Now we can set what type of stars we want, there’s a whole bunch of different options that you can look through, I’m going to go ahead and leave that at the default and then there’s options to choose what value to display. So in this case we’re going to use the average vote and that’s the text to display under the stars as well and we’ll start with just that.

So I’m going to save it and come back to the first test article and you can see I can now rate this article so I go ahead and rate it, it says that the average vote is 3, I can hop over here and login as my test user and you could do this with anonymous user as well, I’ just using authenticated but it is possible to make this work with anonymous and go to test article 1 and you can see the average, I can change my vote but it still just displays the average so even if I change it to 5 now let’s just show mine but it will save the averages for it.

You can change how that display ends up showing up by going back into the content type and you can show it so it will display both the users and the average vote if we wanted and that you can also have it show other things as well but we’ll go through this one quickly, if I hop back over here and refresh the page you can see it shows the average and your rating.

So we’re going to change that back up quick so just to show average. And now the next step is to make it so it forces you to leave a comment in order to rate the item. The first thing we need to do is in this Manage Display come back into the settings and uncheck this expose this filter field for voting.

This will make it so you will not be able to actually vote on the field. So if I come back here it should display looks like showing the average is not exposed for voting because that’s updating and let’s make sure we save it. There we go, you’ll notice I’m no longer able to vote on this through here.

So now we need to add this stars field or this ratings field to the comment form and then you need to link it up so the comment form actually affects the actual average rating of the entire piece of contents.

So we’ll come back to the comment field and this is important if you want to add an existing field so you want to find the 5 star rating field, in this case the Article Rating field that we created and this time for the widget you want to have stars rated while editing because you are seeing the comment edit form so you want to be able to actually change it while you’re editing the comment or creating the comment.

So we’ll go ahead and click Save, you can select the star display options which will leave this at the default, you probably want to make sure they matched up, especially make sure the number of stars matches up between the content type and the comment, the voting target you want to select the parent node, that way each comment as it’s voted will filter out to the node level and you will affect the average that way.

So I’m going to move the rating field around a little bit and you then want to come into Comment Display so we’re going to change the display to show the rating above the comment, we’re going to keep the format as stars, we’re going to then change this to show the users vote instead of the average vote.

So we’ll save this and we’re now going to give this a quick go. One thing you want to make sure is make sure that in the Permissions, authenticated users have the ability to view and post comments, by default they should but you want to make sure of that. We’ll first create one using the admin account so we’ll come to test article 2, you’ll notice I can’t change the rating here but I can leave a rating on the comment form so I’ll go ahead and save it and you’ll notice here’s my rating is 4, it’s my comment and it also changes the average comment of the article.

Now I come in as the other user, I come to the test article 2, you can see the average is 4, I can see the comment and this person rated it 4 and then I can put in my rating. Now you can see there’s two different ratings, you can see the average is now accurately displayed.

So that’s really all there is to the 5 Star Module, you can do a whole bunch more with it of course but what it allows you to do is quickly and easily setup a rating system to rate various types of content on your Drupal website. So that’s it for today on the Daily Dose of Drupal, as always follow me on Twitter and Google +, I’ll see you next time.


hi! nice tutorial... but how do i setup fivestar module to send out notification to user who's their comments or content(node) being rated? i know this may be a diffferent topic but hoping you may share some idea.


You should be able to set up something like this using the rules module. When a user posts a comment on a specific type of content, you can trigger the sending of an email to the user that created the content.

Thanks for the comment.

Nice tutorial... but i setup five star module and profile2 module and i have to comments on user profile page. i know this may be a different topic but hoping you may share some idea.


Is there a way or perhaps another module that will collect a rating for content? Like if you are having users post content and you want them to rate it Like G, PG, PG-13, R, X etc. That way other users will only see the content of the rating they choose or below.


Ashley :)

Hi, first off thanks for the post and the video. Great stuff. But for some reason the ratings don't show up once they are submitting, only the comments do.

If I click to edit the comments I can see the rating, but it does not show up when viewing the whole node. Do you have any idea what could be causing this? I'm using the "Orange" theme if you think that may be an issue.

Can you create a rule to send emails based on who voted for a specific content? I am struggling to find how to populate the voters email address.

Post new comment