Views Work v1.0
Track pageviews and content popularity in Craft CMS
More Craft plugins

Sort by pageviews / popularity

You can very easily get popular content sorted by views today, week or month from Twig:


{% set query = craft.entries.section('..').limit(5) %}
{% do craft.views_work.sortPopular(query) %}
{% set entries = query.all %}

# below are some examples of other sort statements, replace the '{% do craft.views_work.sortPopular...'
# statement above with one of the statements below

# sort popular items by week, monthly or daily views
{% do craft.views_work.sortPopular(query, 'week') %}
{% do craft.views_work.sortPopular(query, 'month') %}
{% do craft.views_work.sortPopular(query, 'day') %}

# exclude items with 0 views
{% do craft.views_work.sortPopular(query, 'week', {min_views: 1}) %}

# only return items with more than 100 views
{% do craft.views_work.sortPopular(query, 'week', {min_views: 100}) %}