0

I have enabled Count content views in Statistics. enter image description here

The bottom of article show "3 reads".

I checked the code, the code is <span>3 reads</span>

Because the number and word is together, I can't change word "reads" to an "eye" icon.

How do I show the number with icon.

enter image description here

Below is the effect I want

enter image description here

  • Please provide the Drupal version? – Yogesh Dec 8 '16 at 4:25
  • Drupal 7 @Yogesh – JJ12345 Dec 8 '16 at 5:26
2
+50

Assuming you're using D7, you can implement hook_node_view() in your custom module and override statistics count text as per your requirement. Check example below:

/**
 * Implements hook_node_view().
 */
function [YOUR_MODULE_NAME]_node_view($node, $view_mode) {
  if ($view_mode != 'rss') {
    if (user_access('view post access counter')) {
      $statistics = statistics_get($node->nid);
      if ($statistics) {
        // Alter text as per your requirement below.
        $links['statistics_counter']['title'] = format_plural($statistics['totalcount'], '<i class="icon"></i>1 read', '<i class="icon"></i>@count reads');
        $node->content['links']['statistics'] = array(
          '#theme' => 'links__node__statistics',
          '#links' => $links,
          '#attributes' => array('class' => array('links', 'inline')),
        );
      }
    }
  }
}
  • Thanks. I just looked into the statistic folder and remove the word "read‘ and "reads" in 2 files which are statistics.test and statistics.module. Now it is okay. – JJ12345 Dec 8 '16 at 5:41
  • Do not modify Core statistics module file, this is bad practice and if you update Drupal Core, this will break again. Instead you can implement hook_node_view() in your custom module and override text as per example given above. – Yogesh Dec 8 '16 at 5:50
  • Which file should I edit? – JJ12345 Dec 8 '16 at 6:07
  • You've to create your own custom module, and inside your module's .module file, you need to implement hook_node_view() hook. So suppose if you've created a module named custom_module then you'll implement custom_module_node_view() function in your custom_module.module file. Check how implement hook guide for more details. – Yogesh Dec 8 '16 at 6:13

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.