ExpressionEngine Add-ons

Rating:Rating_Vote_Stats template tag

The Rating:Rating_Vote_Stats tag allows you to display vote statistics for ratings on your entries. In other words, when a user writes a rating/review for a channel entry, that review can then be voted up or down. It's a way for your users to indicate which ratings/reviews they find useful and helpful versus unfair or inappropriate. This function allows you to display the results of all votes for each review. Used in conjunction with the Rating:Insert_Rating_Vote function.

{exp:rating:rating_vote_stats} content {/exp:rating:rating_vote_stats}

Parameters

The following parameters are available for use:

duplicate_check_guest_ip=

duplicate_check_guest_ip="no"

This parameter allows you disable IP checking on Guest voting submissions. By default, Rating will check for a matching IP address and a cookie. Setting this parameter to no will set Rating to ONLY look for a cookie with a Guest user. While this isn't a complete solution, it solves the issue where multiple users have a shared IP address.

rating_id=

rating_id="{rating_id}"

This parameter tells the function which rating to pull vote statistics for.

Variables

The following variables are available for use:

down_votes

{down_votes}

This variable will display the total number of down votes for the given rating/review.

down_percent

{down_percent}

This variable will display the percent of down votes for the given rating/review.

up_votes

{up_votes}

This variable will display the total number of up votes for the given rating/review.

up_percent

{up_percent}

This variable will display the percent of up votes for the given rating/review.

total_votes

{total_votes}

This variable will display the total number of votes for the given rating/review.

previous_vote

{previous_vote}

This variable will display the vote the currently logged in user gave for a specific rating/review. Will parse as up, down or an empty string if no previous vote was made by the user.

rating_comments

{rating_comments}

When using the Rating:Comments feature, this variable will display the total number of comments submitted to the rating entry.

Conditionals

Conditionals can be run on any of the variables above. Additionally these exist as well:

already_voted

{if already_voted}{/if}

This conditonal will display its contents if the currently logged in user has already voted for a given rating/review.

not_already_voted

{if not_already_voted}{/if}

This conditonal will display its contents if the currently logged in user has not yet voted for a given rating/review.

Examples

The following code example shows the Rating_Votes_Stats tag, which would be placed within the Rating:Entries loop:

<h3>Ratings for this Entry:</h3>
{exp:rating:entries}

    <p><a href="{path=user/profile}/{member_id}/">{screen_name}</a></p>
    <p>{stars}{rating}{/stars}</p>
    <p>Submitted on {rating_date format="%F %j, %Y at %g:%i %a"}</p>
    <p>{review}</p>

    {exp:rating:rating_vote_stats rating_id="{rating_id}"}
        {if not_already_voted}
            <p>
                Vote for this Rating:
                <a href="{path='ratings/vote'}/{rating_id}/up/">Up</a> |
                <a href="{path='ratings/vote'}/{rating_id}/down/">Down</a>
            </p>
        {/if}
        {if already_voted}
            <p>You've already voted for this rating.</p>
        {/if}
        <p>
            This review has received {up_votes} ({up_percent}%) Up votes
            and {down_votes} ({down_percent}%) Down votes
            out of a total of {total} votes.
        </p>
    {/exp:rating:rating_vote_stats}

{/exp:rating:entries}