I've tried every recommendation I can find; I've enabled statistics and advanced statistics and can see that hits are being counted. I can display lists by what nodes are the most hit, etc; but I just want to display the results for the given node I'm on. How can I do this? I suspect the solution is in using contextual filters for a view, but I can't get this working, either. Help appreciated.

Drupal 7.

  • who can see: admin or Anonymous users? – Tritof Jan 21 '15 at 15:30
  • Perhaps this module will help? drupal.org/project/nodeviewcount It exposes its data to Views, I'm not sure whether the core statistics module does... – Beebee Jan 21 '15 at 15:39
  • @tritof Since I want it to be a block, I should be able to customize its visibility any way I want. For me, I just want admins to see it. – WorldsEndless Jan 21 '15 at 17:29
  • @Beebee I've tried it; same problem: shows many pages, not just the one I'm on. – WorldsEndless Jan 21 '15 at 18:28
  • Have you tried using the contextual filter and/or setting up a relationship for the node's ID when constructing the view? – Beebee Jan 21 '15 at 21:57

I couldn't figure out how to do it with contextual filters, so I guess I still don't understand things on that front. However, a custom block with just a couple lines of PHP did the trick. All directions from:

How to get visitors count of a page created using views

As per that post, custom code was:

$path = $_GET['q'];
$visits = db_query("SELECT count(*) FROM {accesslog} where path = :path", array(':path' => $path))->fetchField();
echo "Views: " . $visits;

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.