Display Hits At Joomla! 1.5

E-mail Print PDF

Show Hits at Joomla Category (Section) Pages with Each Item:

You want to show the hits for every article in category page too?

You need to add the following code in your category page:

<?php if ($this->params->get('show_hits')) : ?>
 <span class="articlehits">          
 (Read : <?php echo $this->item->hits; ?> times)
 </span>
<?php endif; ?>

You can change the "Read...times: " with anything you want...

Ideally your joomla template should have html override folder... i.e. you need to open this blog_item.php file, and add the above code where you want to display the hits.

your joomla template > html > com_content > category(section) > blog_item.php

This will work perfectly for you I am sure as we do this daily :-) If you do not know how to edit template or your current tempalte dont have the html override folder, let us know, and one of our coder will do implement this for you.

Show Hits at Frontpage (Main page) of Your Joomla Site:

Just add the above code in the frontpage item i.e.

<?php if ($this->params->get('show_hits')) : ?>
 <span class="articlehits">          
 (Read : <?php echo $this->item->hits; ?> times)
 </span>
<?php endif; ?>

into the following file:

joomla template > html > com_content > frontpage > default_item.php

(Add this in the above file at the position where you want to show the hits)

But to make this code work you need to add one more little code at joomla page i.e.

Open components/com_content/models/frontpage.php

Search for this line at about 128th line:

$query = ' SELECT a.id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, a.sectionid, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by,' .
 ' a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.images, a.attribs, a.urls, a.metakey, a.metadesc, a.access,' .
 ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,'.
 ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'.
 ' CHAR_LENGTH( a.`fulltext` ) AS readmore,' .
 ' u.name AS author, u.usertype, g.name AS groups, u.email as author_email, cc.title AS category, s.title AS section, s.ordering AS s_ordering, cc.ordering AS cc_ordering, a.ordering AS a_ordering, f.ordering AS f_ordering'.
 $voting['select'] .
 ' FROM #__content AS a' .
 ' INNER JOIN #__content_frontpage AS f ON f.content_id = a.id' .
 ' LEFT JOIN #__categories AS cc ON cc.id = a.catid'.
 ' LEFT JOIN #__sections AS s ON s.id = a.sectionid'.
 ' LEFT JOIN #__users AS u ON u.id = a.created_by' .
 ' LEFT JOIN #__groups AS g ON a.access = g.id'.
 $voting['join'].
 $where
 .$orderby
 ;

you need to add this code (a.hits,) at the end before the "'" i.e.

 a.attribs, a.urls, a.metakey, a.metadesc, a.access,

becomes:

a.attribs, a.urls, a.metakey, a.metadesc, a.access, a.hits,

PS. If you want any customization, or this does not work in your situation. You can submit a support ticket at our desk and let one of our expert coder do this for you.

Show Hits at Joomla Article Pages:

You want to show the hits for every article page?

You need to add the following code in your article page:

<?php if ($this->params->get('show_hits')) : ?>
 <span class="articlehits">         
 (Read : <?php echo $this->article->hits; ?> times)
 </span>
 <?php endif; ?>

Ideally your joomla template should have html override folder... i.e. you need to open this default.php file, and add the above code where you want to display the hits.

your joomla template > html > com_content > article > default.php