1. Copy the ajw_comment_rating folder to your system/expressionengine/third_party folder
  2. Go to Add-ons > Extensions and enable the AJW Comment Rating
  3. Install the Extension and Fieldtype


Adding rating field to your comment form

You can add a rating field by simply including a form element with the name rating in your standard EE comment form.


{exp:comment:form channel="..."}
    {if logged_out}
        <div class="row">
            <label for="name">Name: </label>
            <input type="text" name="name" value="{name}" />
        <div class="row">
            <label for="email">Email: </label>
            <input type="text" name="email" value="{email}" />
    <div class="row">
        <label for="rating">Rating: </label>
        <select id="rating" name="rating">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
    <div class="row">
        <label for="comment">Comment: </label>
        <textarea cols="48" rows="6" name="comment">{comment}</textarea>
    <div class="row">
        <input type="submit" name="submit" value="Submit" />

Displaying ratings in the comments list

You can display the rating in EE's comment list display using the {rating} variable. The {if rating}...{/if} conditional is also available.


{if rating}{rating}{if:else}unrated{/if}

Adding a custom field to you entries

In order to aggregate the comment ratings into an average for the entry, you need to add a new custom field to the channel's field group.

To do this, go to the field group under Admin > Channel Fields, choose the appropriate group and click the Create a New Channel Field button.

Select AJW Comment Rating for the field type and name it as you desire. Under the Field Options section you can choose the field label (use rating unless you have configured the comment form differently - see below), and choose the value you want to store in this field (eg, Average rating)

When you create (or edit) this field it will look through all existing entries and update this field with the chosen value (ie, the average rating for each entry).

When new ratings are added it will automatically update these custom fields, keeping an up-to-date record of rating values within the entry.

Having the value in the entry makes it much easier to display (you can use normal template tags) and makes the display much more efficient (the calculation is only performed once, when a rating is added, rather than each time it is displayed).

It also allows you to use the value in the channel entries tag, most likely for sorting by rating.

When displaying the fieldtype there is an optional round= parameter that you can use to control how many decimal places are displayed, eg,

{rating round="1"}

will display the average rating to 1 decimal place (eg, 4.5).

There is also an optional parameter multiply= that allows you to provide a value to multiply the rating by. This is useful, for example, generating a percentage from the rating. If the rating is 3 out of 5, using the variable

{rating multiply="20"}

will give a value of 60.

Add multiple rating fields

Multiple ratings can be used per comment, eg, Quality, Value for Money, Overall rating.

Each rating needs to have its own unique rating label. By default, the rating label rating is used. If you want to use a different label, or use multiple labels you need to tell the add-on the values you want to use.

You do this in 2 places:

The comment form

This is done by including a hidden input element called rating_labels. The value should be a pipe (|) separated list of the labels. To use the fields rating and like the hidden input element should be:

<input type="hidden" name="rating_labels" value="rating|like">

The comment list

To tell the comment list which variables to replace or to use as conditionals you need to include the parameter rating_labels to the the comment entries tag:

{exp:comment:entries sort="asc" rating_labels="rating|like"}

You can now use the {rating} and {like} variables and conditionals.