web design, England, Britain, UK, belgium
 
Ulti Clocks content

How to display the number of article hits in the Article layout - Joomla 1.5

GJC Web Design Joomla & VirtueMart how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help

A collection of help articles and coding examples for Joomla & Virtuemart

Belgium, VirtueMart & Joomla Web Design England UK Britain & Germany

Joomla, VirtueMart, how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help sand Display the number of page views (hits) for an article within the normal Joomla Article layout.
article, php, date, hits, modified, endif, jtext, joomla, pre, echo, params, number, times, class, xml, jhtml, intval, modify, format, looks, com, sprintf, div, content, display, span, modifydate, html, read, updated, float, right, accessed, displayed, style, moved, add, conditional, clause, need

Home Joomla - VirtueMart Joomla & VM How To's How to display the number of article hits in the Article layout - Joomla 1.5

Sat

18

Apr

How to display the number of article hits in the Article layout - Joomla 1.5

  • Joomla 1.5
  • com_content

This change will display the number of times each article has been read (hits) in the Joomla 1.5 Article layout.

You can see how it looks on the article pages.


Open file joomla_root/components/com_content/views/article/tmpl/default.php in any text editor and go to line 130.
The table row were interested in looks like this -
 
<?php if ( intval($this->article->modified) !=0 && $this->params->get('show_modify_date')) : ?>
<tr>
  <td class="modifydate">
    <?php echo JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->article->modified, JText::_('DATE_FORMAT_LC2'))); ?>
  </td>
</tr>
<?php endif; ?>
 
You need to add the conditional clause to display the number of hits for the article.
The <?php endif; ?> have been moved as well -
 
<?php if ( intval($this->article->modified) !=0 && $this->params->get('show_modify_date')) : ?>
<tr>
  <td class="modifydate">
    <?php echo JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->article->modified, JText::_('DATE_FORMAT_LC2'))); ?>
    <?php endif; ?>
    <?php if ($this->params->get('show_hits')) : ?>
      <span style="float:right;">          
         Read : <?php echo $this->article->hits; ?> times
      </span>
    <?php endif; ?>
  </td>
</tr>
 
Now the number of times the article has been accessed (hits) is displayed.


Add this page to your favorite Social Bookmarking websites
Digg! Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! Slashdot! Technorati! StumbleUpon! Spurl! Newsvine! Furl! Fark! Yahoo! Netvouz! Mister-Wong! RawSugar! Ma.gnolia! Squidoo! DZone! Swik!
Last Updated on Saturday, 18 April 2009 14:07 Read : 7178 times
 
Comments (7)
It doesn't work for me
7 Thursday, 18 March 2010 11:41
Me
It doesn't work for me Embarrassed
Great
6 Tuesday, 16 March 2010 09:36
Horhat Kund
Thanks for the help Smile
Thanks
5 Thursday, 25 February 2010 19:49
flashfs
Very informative, thanks.
Hint: if you change and nothing happens, check if your layout already has a com_content override at /template/layout_name/html/com_content/article/default.php
Piseth
4 Thursday, 18 February 2010 10:04
GJC(admin)
The problem is that the hits have to be stored somewhere and unless it's an article then the hits aren't stored.
Try making the link go to a page that has the pdf to download.
Then use my plugin http://www.gjcwebdesign.com/page-views-in-content.html to report the hits..
Thanks
3 Thursday, 18 February 2010 01:46
Piseth
Thank you for your article. It works for me. Anyway, I am trying to look for a way to show it for specific link. For example, I add a pdf file for download. Then at the end of the link I want to show # of hits. See my example below:

(Title)WMC Annual Report Download ### times
Description: sdfjalsdfjoweuraslkdjfoqwejlaskhgfoqwjsadf
asfhasodfjwoeiufaskljdglkajdsfjasdklf

In this case, can you help me. (for joomla)

or just like your below
Home page hits
2 Thursday, 13 August 2009 19:13
GJC (admin)
This will never work for a blog style home page as it's dynamic and the hits are not stored anywhere.
You could add a similar code to the com_content/views/frontpage/tmpl/default_item.php and have the number of hits per article.
Haven't tried it but it would be something like item->hits; ?>
Article Hit Counter
1 Wednesday, 12 August 2009 11:35
Sadik Shahriar
Hi I have successfully done with the articles but not for the front page. I have tried to copy and paste your code to

C:\Program Files\xampp\htdocs\Joomla\components\com_content\views\frontpage\tmpl\default_item.php

on line 96. It works fine for the Last Update showing but hit counter does not work. Will you help me in this issue?

Add your comment

BoldItalicUnderlineStrikethroughSubscriptSuperscriptEmailImageHyperlinkOrdered listUnordered listQuoteCodeHyperlink to the Article by its id
Very HappySmileWinkSadSurprisedShockedConfusedCoolLaughingMadRazzEmbarrassedCrying or Very SadEvil or Very MadTwisted EvilRolling EyesExclamationQuestionIdeaArrowNeutralMr. GreenGeekUber Geek
Your name:
Subject:
Comment:

Latest Articles

Paypal Donation

If you use this module on your site please donate a small amount.
Any donation amount appreciated.

VM Live Product Search

Recommended Reading

For those interested in extending there knowledge of Joomla! & VirtueMart Packt Publishing has an excellent range of help & how to books.
Listed below are some I can recommend.
Simply click on the images to be taken directly to their web shop.

Learning Joomla! 1.5 Extension Development Learning Joomla! 1.5 Extension Development
by Joseph L. LeBlanc.
Read the review
Joomla! E-Commerce with VirtueMart Joomla! E-Commerce with VirtueMart
by Suhreed Sarkar.
Read the review
Joomla! Web Security Joomla! Web Security
by Tom Canavan.

Mastering Joomla! 1.5 Extension and Framework Development Mastering Joomla! 1.5 Extension and Framework Development
by James Kennard.

Joomla! Template Design: Create your own professional-quality templates with this fast, friendly guide Joomla! Template Design: Create your own professional-quality templates with this fast, friendly guide
by Tessa Blakeley Silver.

GJC Web Design Joomla & VirtueMart how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help

A collection of help articles and coding examples for Joomla & Virtuemart

Belgium, VirtueMart & Joomla Web Design England UK Britain & Germany

Joomla, VirtueMart, how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help



How to display the number of article hits in the Article layout - Joomla 1.5



Display the number of page views (hits) for an article within the normal Joomla Article layout.


article, php, date, hits, modified, endif, jtext, joomla, pre, echo, params, number, times, class, xml, jhtml, intval, modify, format, looks, com, sprintf, div, content, display, span, modifydate, html, read, updated, float, right, accessed, displayed, style, moved, add, conditional, clause, need