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.

Logo

Publisher

  • Manual
  • Cookbooks
    • Templates Cookbooks
      • Users registration and login
      • Create new route with extension (example: feed/sitemap.rss)
      • Create new custom route
      • Most popular (read) articles list
      • Elements generated on theme installation
    • Technical Cookbooks
    • Editors Cookbooks
    • Implementators Cookbooks
  • Reference
  • Bundles
  • Developer Guide

Related Topics

  • Documentation overview
    • Cookbooks
      • Templates Cookbooks
        • Previous: Create new custom route
        • Next: Elements generated on theme installation

Quick search

©2018, Sourcefabric z.ú. | Powered by Sphinx 1.8.6 & Alabaster 0.7.12 | Page source