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. TopLiked

TopLiked snippet

Lists objects with the highest like counts. Sorted by the likes field in the aggregates table.

Parameters

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

Chunk placeholders

PlaceholderDescription
[[+idx]]Row number (1, 2, 3…)
[[+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

Periods

ValueWindow
dayLast 24 hours
weekLast 7 days
monthLast 30 days
yearLast 365 days
allAll time (from the aggregates table)

For periods other than all, the component rebuilds the top from raw reaction rows in that window.

Examples

Add the <ul class="reactions-top"> wrapper yourself: the row chunk outputs <li>…</li>.

Resources: week / limit

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

Periods day · week · month · year · all

Same call, only period changes:

modx
[[!TopLiked? &period=`day` &limit=`5`]]
[[!TopLiked? &period=`month` &limit=`5`]]
[[!TopLiked? &period=`all` &limit=`10`]]
fenom
{'!TopLiked' | snippet : ['period' => 'day', 'limit' => 5]}
{'!TopLiked' | snippet : ['period' => 'month', 'limit' => 5]}
{'!TopLiked' | snippet : ['period' => 'all', 'limit' => 10]}

miniShop3 products

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

Row title and URI come from ObjectLookup / the STI resource. Short msProduct is fine.

web context filter

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

To a placeholder

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

Custom row chunk

modx
<ul class="top-liked">
[[!TopLiked?
    &period=`week`
    &limit=`10`
    &tpl=`tpl.top.row`
]]
</ul>
fenom
<ul class="top-liked">
{'!TopLiked' | snippet : [
    'period' => 'week',
    'limit'  => 10,
    'tpl'    => 'tpl.top.row',
]}
</ul>

Tickets comments

Not verified on MODX 3:

modx
[[!TopLiked? &class=`TicketComment` &period=`month` &limit=`5`]]
fenom
{'!TopLiked' | snippet : [
    'class'  => 'TicketComment',
    'period' => 'month',
    'limit'  => 5,
]}