Skip to content
Reactions
Reactions
Universal reactions for MODX 3 — likes, GitHub-style sets, tops and trending on any object
  1. Extras
  2. Reactions
  3. Snippets
  4. TopRated

TopRated snippet

Lists objects with the highest rating. Rating = likes − dislikes (up/down balance).

Parameters

ParameterDefaultDescription
classmodResourceclass_key of objects in the selection
periodallPeriod: day, week, month, year, all
limit10Maximum items
context(empty)Context filter
tpltpl.Reactions.topChunk for one list row
toPlaceholder(empty)Placeholder name instead of direct output

Chunk placeholders

PlaceholderDescription
[[+idx]]Row number
[[+object_id]]Object ID
[[+class_key]]Object class (in the DB: object_class)
[[+pagetitle]]Resource title / product name
[[+uri]]Object URL (or empty)
[[+likes]]Like count
[[+dislikes]]Dislike count
[[+total]]Sum of all reactions
[[+rating]]Rating (likes − dislikes)
[[+trending_score]]Trending score

Examples

Sorted by rating (= likes − dislikes). Same periods as TopLiked: day / week / month / year / all.

Resources for a chosen period

modx
<ul class="reactions-top">
[[!TopRated?
    &class=`modResource`
    &period=`week`
    &limit=`5`
]]
</ul>
fenom
<ul class="reactions-top">
{'!TopRated' | snippet : [
    'class'  => 'modResource',
    'period' => 'week',
    'limit'  => 5,
]}
</ul>

Month and year

modx
[[!TopRated? &period=`month` &limit=`10`]]
[[!TopRated? &period=`year` &limit=`10`]]
fenom
{'!TopRated' | snippet : ['period' => 'month', 'limit' => 10]}
{'!TopRated' | snippet : ['period' => 'year', 'limit' => 10]}

miniShop3 products

modx
<ul class="reactions-top">
[[!TopRated?
    &class=`msProduct`
    &period=`year`
    &limit=`8`
]]
</ul>
fenom
<ul class="reactions-top">
{'!TopRated' | snippet : [
    'class'  => 'msProduct',
    'period' => 'year',
    'limit'  => 8,
]}
</ul>

To a placeholder + custom chunk

modx
[[!TopRated?
    &period=`all`
    &limit=`3`
    &tpl=`myTopRatedRow`
    &toPlaceholder=`rx.rated`
]]
<ul class="reactions-top">[[+rx.rated]]</ul>
fenom
{'!TopRated' | snippet : [
    'period' => 'all',
    'limit'  => 3,
    'tpl' => 'myTopRatedRow',
    'toPlaceholder' => 'rx.rated',
]}
<ul class="reactions-top">{$_modx->getPlaceholder('rx.rated')}</ul>

web context

modx
[[!TopRated? &period=`all` &context=`web` &limit=`20`]]
fenom
{'!TopRated' | snippet : [
    'period'  => 'all',
    'context' => 'web',
    'limit'   => 20,
]}

Tickets comments

Not verified on MODX 3:

modx
[[!TopRated? &class=`TicketComment` &period=`week` &limit=`3`]]
fenom
{'!TopRated' | snippet : [
    'class'  => 'TicketComment',
    'period' => 'week',
    'limit'  => 3,
]}

TopLiked vs TopRated

SnippetSortWhen to use
TopLikedBy likes“Most popular”: many positive reactions
TopRatedBy rating“Best”: high like/dislike balance

An article with 100 likes and 95 dislikes ranks in TopLiked but not in TopRated.