Jump to content

Theme customization: showing number of likes and / or dislikes


Tech Support
 Share

Recommended Posts

Rating in KVS is a number from 0 to 5 due to historical reasons. Initially it was a 5-star rating where users could vote not just as "like" or "dislike", but also use other rating values.

In modern themes almost everybody is using likes or dislikes. So do KVS themes. However internally the rating is still calculated as a plain number, where "like" is a 5-star vote and "dislike" is a 0-star vote. By default rating is displayed as % amount of likes using this code:

Inside list block (means for each video / album / model / etc. in the list):

{{assign var="rating" value="`$item.rating/5*100`"}}
{{if $rating>100}}{{assign var="rating" value="100"}}{{/if}}
{{$rating}}%

 

Inside view block:

{{assign var="rating" value="`$data.rating/5*100`"}}
{{if $rating>100}}{{assign var="rating" value="100"}}{{/if}}
{{$rating}}%

 

If you want to change this with the number of likes and dislikes, or show them additionally to % rating, you can use this code:

Inside list block (means for each video / album / model / etc. in the list):

{{assign var="likes" value=0}}
{{assign var="dislikes" value=0}}
{{if $item.rating>0}}
{{assign var="likes" value=$item.rating*$item.rating_amount/5|replace:",":"."|round}}
{{assign var="dislikes" value=$item.rating_amount-$likes}}
{{/if}}
{{$likes}} likes and {{$dislikes}} dislikes

 

Inside view block:

{{assign var="likes" value=0}}
{{assign var="dislikes" value=0}}
{{if $data.rating>0}}
{{assign var="likes" value=$data.rating*$data.rating_amount/5|replace:",":"."|round}}
{{assign var="dislikes" value=$data.rating_amount-$likes}}
{{/if}}
{{$likes}} likes and {{$dislikes}} dislikes
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...