Rating 2.0 Stats

The rating stats tag takes an entry id as a parameter and returns rating statistics for the given blog post in the format you specify. You can use this function in any place that you can pass to it an entry id.

Parameters

entry_id

entry_id = "some_entry_id"

The 'entry_id' parameter allows you to override the entry id or url title pulled from the url of the page. In those cases where your page shows a number of weblog entries, each of which you want to show stats, you should supply this parameter by feeding into it the entry_id variable from your weblog:entries tag. Like this entry_id="{entry_id}".

form_name

form_name = "some_name"

The 'form_name' parameter allows you to show a subset of rating stats. If you provided a form name in your rating submission form, you can call it here to show only those ratings provided for a given form.

fractions

fractions = "."

The 'fractions' parameter allows you to specify what character to use a the decimal place delimiter. The default is a period '.'.

precision

precision = "2"

The 'precision' parameter allows you to specify to how many decimal places ratings should be calculated. The default is '0'.

scale

scale = "5"

The 'scale' parameter is used in conjunction with graphical representations of rating stats. As detailed below, you can show stars, circles or a bar when showing rating averages. These are always a 4 out of 5 type value. Currently only scales of 5 and 10 are allowed.

theme

theme = "some_theme"

The 'theme' parameter is used in conjunction with graphical representations of rating stats. You can use the deafult graphics that come with the Rating module or you can create your own and save them in a separate theme folder in the rating_themes directory. Use this parameter to indicate which theme to use. The default theme is 'default'.

thousands

thousands = ","

The 'thousands' parameter allows you to specify what sort of separator to use between groups of thousands in rating sums and rating counts. The default is a comma ','.

Variables

The following variables are available with the {exp:rating:stats} tag.

overall_count

{overall_count}

The 'overall_count' variable will be replaced by the total count of all numeric ratings. If you have provided the form_name parameter, the overall count will be limited to ratings provided in the given form.

overall_sum

{overall_sum}

The 'overall_sum' variable will be replaced by the sum of all numeric ratings. If you have provided the form_name parameter, the overall sum will be limited to ratings provided in the given form.

overall_avg

{overall_avg}

The 'overall_avg' variable will be replaced by the average of all numeric ratings. If you have provided the form_name parameter, the overall average will be limited to ratings provided in the given form.

count_custom_field

{count_custom_field}

You can show the total count of ratings for a given numeric field by using the count_ + custom_field_name pattern. Adding the prefix of 'count_' tells the Rating module to provide a count of the custom field that you name. If you have provided the form_name parameter, the count will be limited to ratings provided in the given form.

sum_custom_field

{sum_custom_field}

You can show the sum of ratings for a given numeric field by using the sum_ + custom_field_name pattern. Adding the prefix of 'sum_' tells the Rating module to provide a sum of the custom field that you name. If you have provided the form_name parameter, the sum will be limited to ratings provided in the given form.

avg_custom_field

{avg_custom_field}

You can show the average of ratings for a given numeric field by using the avg_ + custom_field_name pattern. Adding the prefix of 'avg_' tells the Rating module to provide an average of the custom field that you name. If you have provided the form_name parameter, the average will be limited to ratings provided in the given form.

stars_overall_avg

{stars_overall_avg}

The 'stars_overall_avg' variable will be replaced by a graphical representation of the overall average of ratings for a given weblog entry. Only if you specify a value in the scale parameter of either 5 or 10 will this variable work. You can customize the graphics used by adding additional theme images to the rating_themes folder in your site and referring to one of these theme folders with the theme parameter.

circles_overall_avg

{circles_overall_avg}

The 'circles_overall_avg' variable will be replaced by a graphical representation of the overall average of ratings for a given weblog entry. Only if you specify a value in the scale parameter of either 5 or 10 will this variable work. You can customize the graphics used by adding additional theme images to the rating_themes folder in your site and referring to one of these theme folders with the theme parameter.

bar_overall_avg

{bar_overall_avg}

The 'bar_overall_avg' variable will be replaced by a graphical representation of the overall average of ratings for a given weblog entry. Only if you specify a value in the scale parameter of either 5 or 10 will this variable work. You can customize the graphics used by adding additional theme images to the rating_themes folder in your site and referring to one of these theme folders with the theme parameter.

stars_avg_your_field

{stars_avg_your_field}

For each of your numeric rating fields, you can show a graphical representation of their avergage for a given entry by using the 'stars_avg_your_field' variable. Only if you specify a value in the scale parameter of either 5 or 10 will this variable work. You can customize the graphics used by adding additional theme images to the rating_themes folder in your site and referring to one of these theme folders with the theme parameter.

circles_avg_your_field

{circles_avg_your_field}

For each of your numeric rating fields, you can show a graphical representation of their avergage for a given entry by using the 'circles_avg_your_field' variable. Only if you specify a value in the scale parameter of either 5 or 10 will this variable work. You can customize the graphics used by adding additional theme images to the rating_themes folder in your site and referring to one of these theme folders with the theme parameter.

bar_avg_your_field

{bar_avg_your_field}

For each of your numeric rating fields, you can show a graphical representation of their avergage for a given entry by using the 'bar_avg_your_field' variable. Only if you specify a value in the scale parameter of either 5 or 10 will this variable work. You can customize the graphics used by adding additional theme images to the rating_themes folder in your site and referring to one of these theme folders with the theme parameter.

Variable Pairs

The following variable pair is available with the {exp:rating:form} tag.

rating_fields

{rating_fields}{/rating_fields}

This variable pair makes it easy for you to show all of your rating fields. You can run conditionals to show different formatting depending on field type. These conditionals are available:

{if field_type == 'numeric'}{/if} This conditional determines the type of field; numeric, textarea or text.

These variables are available:

{field_name} {field_label} {field_maxl} This is the maximum field length. {field_order}

Conditionals

The following conditionals are available with the {exp:rating:stats} tag.

if overall_count

{if overall_count > "10"}{/if}

This conditional allows you to evaluate the overall count of ratings for a given entry. You can check for greater than and less then values as well as equality to some other value.

if overall_sum

{if overall_sum < "45"}{/if}

This conditional allows you to evaluate the overall sum of ratings for a given entry. You can check for greater than and less then values as well as equality to some other value.

if overall_avg

{if overall_avg > "3"}{/if}

This conditional allows you to evaluate the overall avg of ratings for a given entry. You can check for greater than and less then values as well as equality to some other value.

if count_some_field

{if count_some_field > "10"}{/if}

This conditional allows you to evaluate the count of a given rating field for a given entry. You can check for greater than and less then values as well as equality to some other value.

if sum_some_field

{if sum_some_field > "10"}{/if}

This conditional allows you to evaluate the sum of a given rating field for a given entry. You can check for greater than and less then values as well as equality to some other value.

if avg_some_field

{if avg_some_field > "3"}{/if}

This conditional allows you to evaluate the avg of a given rating field for a given entry. You can check for greater than and less then values as well as equality to some other value.

Examples

{exp:weblog:entries weblog="hotels" limit="20" orderby_ratings="desc" rdf="off" disable="categories|pagination|trackbacks"}
<tr>

<td>{title}</td>

<td>
<div class="rating-indicator">
{exp:rating:stats entry_id="{entry_id}" theme="default"}{stars_overall_avg}
<p class="attributes">Based on {overall_count} review{if overall_count !="1"}s{/if}</p>
{/exp:rating:stats}
</div>
</td>

</tr>
{/exp:weblog:entries}