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 UK 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
 

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:
  The word for verification.
Lowercase letters only with no spaces.

The word for verification.<br/>Lowercase letters only with no spaces.
Word verification:

Subject:
Comment:
Comments (11)
@Ingus
11 Tuesday, 12 April 2011 07:54
GJC Admin
You would need to replace the 2 words with JText constants and and put them in the language files
JPageviews in multilanguage pages
10 Tuesday, 12 April 2011 04:02
Ingus
Hi,
Great plugin! Works perfect!
But how can I translate the text before and after number of hits in multilanguage pages?
nope..
9 Thursday, 31 March 2011 04:21
Jeff
no good - tried on Joomla 1.5 - default installation - http 500 server error.
thats great
8 Thursday, 26 August 2010 13:52
Vinicius
tks so much! Smile
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?

Our Recommended Reading

For those interested in extending their 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.


Joomla! Social Networking with JomSocial
Joomla! Social Networking
with JomSocial

by Kwasi Boateng & Beatrice A. Boateng.
Joomla! 1.5 Multimedia
Joomla! 1.5 Multimedia
by Allan Walker.


Building job sites with Joomla!
Building job sites with Joomla!
by Santonu Kumar Dhar.

Joomla! Template Design: Create your own professional-quality templates with this fast, friendly guide
Joomla! Template Design: 2nd Edition
Create your own professional-quality
templates with this fast, friendly guide
by Tessa Blakeley Silver.
Magento: Beginner's Guide
Magento: Beginner's Guide by William Rice
is a must for anyone trying the
open-source e-Commerce solution.

Read the review

object-oriented-javascript-applications-libraries
Object-Oriented JavaScript by
Stoyan Stefanov gives you a very
comprehensive grounding in
the latest Javascript techniques.

Read the review
Joomla! Web Security
Joomla! Web Security
by Tom Canavan.

Joomla 1.5 Top Extensions Cookbook
Joomla 1.5 Top Extensions Cookbook by
Suhreed Sarkar is an ideal and concise round up of the extensions available for the Joomla! system.

Read the review

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.

Mastering Joomla! 1.5 Extension and Framework Development
Mastering Joomla! 1.5 Extension and
Framework Development : 2nd Edition

by James Kennard.
Read the review

Building job sites with Joomla!
Building job sites with Joomla!
by Santonu Kumar Dhar.
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! 1.5 Site Blueprints Joomla! 1.5 Site Blueprints
by Timi Ogunjobi.

Joomla! 1.5 JavaScript jQuery Joomla! 1.5 JavaScript jQuery
by Jose Argudo Blanco.
Read the review
Joomla! Social Networking with JomSocial Joomla! Social Networking with JomSocial
by Kwasi Boateng & Beatrice A. Boateng.

Joomla! 1.5 Multimedia Joomla! 1.5 Multimedia
by Allan Walker.

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 : 2nd Edition
by James Kennard.

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

Magento: Beginner's Guide
Magento: Beginner's Guide by William Rice
is a must for anyone trying the
open-source e-Commerce solution.

Read the review

GJC Web Design UK 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