Most popular (read) articles list¶
Article meta have property articleStatistics and inside it You can find pageViewsNumber. To simplify syntax for ordering we created pageViews alias.
Here is example how to order articles by their page views number:
1 2 3 | {% gimmelist article from articles|order('pageViews', 'desc') %} <!-- ordering by page views -->
<a href="{{ url(article) }}">{{ article.title }}</a>
{% endgimmelist %}
|
There is also option to get most popular (ordered by page views) articles from date range.
For example this is how You can list yesterday most popular articles:
1 2 3 | {% gimmelist article from articles|order('pageViews', 'desc')|dateRange('now', '-1 day') %}
<a href="{{ url(article) }}">{{ article.title }}</a>
{% endgimmelist %}
|
Filter dateRange takes two parameters compatible with PHP strtotime syntax (http://php.net/manual/en/function.strtotime.php):
- start date (<= equal or in past ) - time will be reset to 23:59:59
- end date (>= equal or in feature) - time will be reset to 00:00:00
So |dateRange('now', '-1 day') will filter all page views from whole day today and whole yesterday (from midnight)
To activate article page views counting you need to call short twig function.
1 | {{ countPageView(gimme.article) }}
|
It will print <script> tag with some generated by Publisher javascript code inside.