Views Work v2.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('..').orderByPopular('total', 1).limit(5) %}
{% 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
{% set query = craft.entries.section('..').orderByPopular('week', 1).limit(5) %}
{% set query = craft.entries.section('..').orderByPopular('month', 1).limit(5) %}
{% set query = craft.entries.section('..').orderByPopular('day', 1).limit(5) %}

# also include items with 0 views
{% set query = craft.entries.section('..').orderByPopular('week', 0).limit(5) %}

# only return items with more than 100 views
{% set query = craft.entries.section('..').orderByPopular('week', 100).limit(5) %}

OLD API <v1.3

The api has changed at version 1.3, but the old api still remains functional.


{% 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}) %}