I've seen some news websites that in every news page/node has a page views counter.
For an example a small icon and next to that icon the number of page views. When I refresh that page I can see that counter increases by one immediately, so that's page hits. How can I do this with Drupal website?

Is it possible to display counter page hits as a field with Views?

Comments

satvision83’s picture

I found a way how to do this.
First the core module statistics module has to be activated and marked views count, and then with Views/ field Views counter will be visible.

On the full content, without using views the counter appears in the footer area of the node, as I can see that with firebug. I'm searching a way to create a field with counter, so that will be able to move on the top position next to the title.

vm’s picture

you cannot turn it in to a field. What you may want to investigate is how to print the data manually in the tpl.php file.

satvision83’s picture

Yes, thank you for the tip.
I've changed the place for print render($content['links']); (node.tpl.php) to inside the content, not the footer and now the views counter is over the content.
That's what I wanted.

vm’s picture

the reads data is printed through links, however so is the add comment link and others. If you are fine with all output being above the content you are fine. If not, I suggest inspecting the $content variable further (using devel if necessary) and investigating the printing of reads manually.

satvision83’s picture

No, I've changed the place only for print render($content['links']); and change it a bit. All other input are fine, the comments too. Here what did I change:

Previous:

<div class="content"<?php print $content_attributes; ?>>
    <?php
      // Hide comments, tags, and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
      hide($content['field_tags']);
      print render($content);
    ?>
  </div>
  <?php if (!empty($content['field_tags']) || !empty($content['links'])): ?>
    <footer>
      <?php print render($content['field_tags']); ?>
      <?php print render($content['links']); ?>
    </footer>
  <?php endif; ?>

After:

<div class="content"<?php print $content_attributes; ?>>
    <?php
      // Hide comments, tags, and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
      hide($content['field_tags']);
	  print render($content['links']);
      print render($content);
    ?>
  </div>
  <?php if (!empty($content['field_tags']) || !empty($content['links'])): ?>
    <footer>
      <?php print render($content['field_tags']); ?>
      
    </footer>
  <?php endif; ?>
nevets’s picture

You can turn a view into a field using a module like eva or Display Suite