Jump to content

Page Ratings

Marvin Scharle

Recommended Posts

Hi everybody,

I'd like to share with you another new module. It helps you to manage user ratings for pages in a very simple way.

You can add a user rating to a certain page with a line of code:


If the user is logged in, the module remembers which page the user has rated for. For non-logged-in visitors, the module stores the pages, the user has rated, in the session. 

You can get a page's rating and its total amount of votes in a similar way:

$page->ratings->average;      // => 3.2
$page->ratings->count;        // => 5

For more information about this module, please check out its GitHub repository.

You can check out a working version of the module here: http://curium-cte.lightningpw.com

Edit: The module is now available in the ProcessWire modules directory.

Update: Ratings has been updated to version 1.1, including a new, simpler API accessor. 

As always - please comment for bugs or feature wishes.

Thanks in advance,


Edited by Marvin Scharle
  • Like 20
Link to comment
Share on other sites

Hi Nico,

nice question. I was unclear about this. 

Basically, the ratings are saved to the database, but the information about which pages the user has rated is stored in the session for guests. 

This is just how the module handles preventing guests rating the same page again after a short period of time. 

  • Like 1
Link to comment
Share on other sites

Hello again!

We've just updated Ratings to Version 1.1, which includes a simpler, more unified API.

You can access all API methods via the ratings property.


$page->ratings->average;   // => 4.4
$page->ratings->count;     // => 12

The changes should appear soon in the ProcessWire modules directory. Please check out our GitHub repository for more details.

  • Like 5
Link to comment
Share on other sites

  • 1 month later...

I am playing around with your module, using your example here. However I keep getting a "Use of undefined constant ​ - assumed" in my functions file at the closing line when including the "renderRating" function. I can't figure out. I am sure its user error. Any help is appreciated. Great module, thanks for sharing it.

Link to comment
Share on other sites

  • 2 weeks later...

This is up to you. The module doesn't generate markup so you could just trigger the PHP call when a user clicks on a star.

Theoretical, you fire a Javascript event when the users clicks the star together with the value (1,2,3,4,5) of the star. Then your code adds this rating.

Link to comment
Share on other sites

  • 2 months later...

Thank guys for this module - it was great to quickly set up a ratings system.

A couple of thoughts though.

  1. I am not sure why it needs to be an autoload module - I'd rather you simply load it manually in a template file when you want to use it.
  2. I am not sure why it isn't simply a custom fieldtype that can be added to templates as needed - the way you have done it seems to work just fine, but the one issue I am having is that it can't be used as easily in all situations - for example, you can't select "rating" as an option when configuring a custom view with ListerPro. I am sure there are also other situations where it would be preferable to be a fieldtype, but maybe there are advantages to the approach you have taken that I am not thinking about.
  3. Of course if #2 is implemented, then #1 is no longer an issue :)

Any chance you'd consider a bit of a rewrite to make it a fieldtype? if not, please let me know and I'll put something together myself - just trying to avoid duplicate modules that do the same thing :)

Thanks for considering.

  • Like 3
Link to comment
Share on other sites

  • 5 months later...

I am also looking for this as a fieldtype, because I have a Repeater field for different products with ratings.

Also I want to integrate this with the comments fieldtype.

How would I do that?

I found https://processwire.com/talk/topic/10107-fieldtypestarrating/ as an alternative, which is a fieldtype, but it doesn´t handle floats (average ratings) and has no option to use the star rating on the frontend (rating and saving to database).

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

I'd like this as fieldtype also.

Or does anyone has a hint how to place the ratingform/-field at the pageedit form in the be. Would like to integrate user ratings, e.g. in that way the user only sees his own rating to edit.

I haven't played with it myself yet, but does this do what you want?


Link to comment
Share on other sites

  • 3 months later...

Nice module!

I would love to see a feature to allow adding unlimited votes using the api without binding to a user. So for example to put a review form on the site where people (not users!) could vote. Their submitted votes would be processed then using the add() method. Currently it doesn't work because once you use add(), you cannot add another vote with the same user.

Commenting out the body of the current() method in the module seems to work, but an official solution would be nice.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...