2

I'd like to get a view block listing the most viewed articles.

What are the options to do that with drupal 8?

Note: I have activated the core module named 'statistics' and configured 'Increment a counter each time content is viewed.' But I cannot select that field for sorting in Views.

  • I have activated the core module named 'statistics' and configure 'Increment a counter each time content is viewed. ' but i cannot select that field for sorting in views – Matoeil Oct 24 '16 at 10:01
3

After activating the "Statistics" core module and checking the "Count content views" option in /admin/config/system/statistics, as you mention, you can select "Total views" as sort criteria (see screenshot).

enter image description here

  • thanks, have u tried it ? i display the total views on my view ,my counter stay to 0, whatever clicks i make to display the node!? – Matoeil Oct 24 '16 at 13:23
  • @Matoeil, it is indeed necessary to check the "Count content views" option, I have just edited my answer. I have just tried it on a "vanilla" local Drupal 8 install and it is working: The counter is being incremented every time I click on a node and the view is displaying it. – dinopmi Oct 24 '16 at 15:08
  • weird it does not work in my view – Matoeil Oct 24 '16 at 15:10
  • Be careful with the statistics module, it can be a performance hog. Drupal.org recommends disabling it to improve performance: drupal.org/docs/7/managing-site-performance-and-scalability/… It fires db_queries for every node, logged in or logged out. it is constantly firing db queries for every user on every page. logged in and out. And for every teaser on a landing page. If you have twenty or thirty on the landing page, that's a lot of queries. – oknate Nov 4 '16 at 16:27
-3

After enable Statistics module, creating your view and visiting some pages on a different session, make sure you run cron and clear cache to view an updated list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.