Show Hits Any Where ( Frontpage - Category - Article )

Need help with the Administration of your Joomla! 1.5 site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
Hosam Diab
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Tue Feb 19, 2008 12:52 am

Show Hits Any Where ( Frontpage - Category - Article )

Post by Hosam Diab » Tue Dec 23, 2008 7:26 pm

Hi All

i have a solution that seems to be the only one here :D it worked for me in my site ( I Can not Post A link here )

i will make you show every articles hits in 3 levels :
Front Page articles
Category in the Blog Layout
The article itself


First :
For The Blog Layout :

Open components/com_content/views/category/tmpl/blog_item.php
Search where you want the hits to be appear and but :

Code: Select all

 
<?php if ($this->params->get('show_hits')) : ?>
        Views :<?php echo $this->item->hits; ?>Times
<?php endif; ?>
For The Article to show hits :

Open components/com_content/views/article/tmpl/default.php
Search where you want the hits to be appear and but :

Code: Select all

<?php if ($this->params->get('show_hits')) : ?>
    Views :<?php echo $this->article->hits; ?>Times
<?php endif; ?>
For The Front Page to show hits :

Open components/com_content/views/frontpage/tmpl/default_item.php
Search where you want the hits to be appear and but :

Code: Select all

<?php if ($this->params->get('show_hits')) : ?>
   Views :<?php echo $this->item->hits; ?>Times
<?php endif; ?>
And to work in the front Page you need to add a 4 letters to the file :
Open components/com_content/models/frontpage.php
Search for :

Code: Select all

$query = ' SELECT a.id, a.title, a.title_alias, a.introtext, a.fulltext
its a long line
Find

Code: Select all

a.publish_down, a.images, a.attribs,
replace with :

Code: Select all

a.publish_down, a.images, a.attribs, a.hits,
Save and return the file to its location and I'm done and hope you did too :pop

P.s :you can style the output as you like

Hope that i helped with that solution

Any Comment i'm ready to help

thanks

User avatar
PhilOSparta
Joomla! Guru
Joomla! Guru
Posts: 512
Joined: Sun Feb 25, 2007 10:44 pm
Location: New Jersey, USA
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by PhilOSparta » Mon Jan 05, 2009 11:55 pm

Your post sounds interesting. I was searching on how to find the "number of hits to the front page" and found your post which seems to provide a "display of all hits" which will appear on the front page or other places as provided.

Given that the frontpage is the location which gets displayed for e.g. http://www.example.com , do you know which article or location in the joomla system counts the hits for visits to the frontpage?

Thanks for your post, and any other info that you can provide.

Phil

Hosam Diab
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Tue Feb 19, 2008 12:52 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by Hosam Diab » Tue Jan 06, 2009 12:15 am

Hi

Thanks for your reply ( The First For Long Time )

as i got your Q. You need to display a hit counter for the front page it self not as i provided for the articles shown in the front page ???

is that what you need ??

My post is to provide a way to display the hits of the articles in the front page of joomla

i hope i can help you put need more explanation please

thanks again

User avatar
PhilOSparta
Joomla! Guru
Joomla! Guru
Posts: 512
Joined: Sun Feb 25, 2007 10:44 pm
Location: New Jersey, USA
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by PhilOSparta » Tue Jan 06, 2009 1:42 am

Yes, you understand my question. I am looking for a hit count on the front page by itself.
If I go to the Front Page Manager and unpublish all articles that were on the front page, each time someone lands on my site's front page, they will only see the main menu and header but no articles.

Is there a hit counter that tells how many times the front page has been accessed, even though there are no articles published on the front page?

Phil

User avatar
GreatGatsby
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 234
Joined: Tue Oct 02, 2007 2:03 pm
Location: Michigan
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by GreatGatsby » Tue Jan 06, 2009 2:12 am

That's a good question; one I've not heard before. Perhaps you could include a blank, or nearly blank article, hide the title, and publish it to your front page. Use the hits on that always-published-article to do what you need.

Perhaps there's an extension somewhere for general front page hits.
Jason Boyette

User avatar
PhilOSparta
Joomla! Guru
Joomla! Guru
Posts: 512
Joined: Sun Feb 25, 2007 10:44 pm
Location: New Jersey, USA
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by PhilOSparta » Tue Jan 06, 2009 2:44 am

GreatGatsby wrote:Perhaps you could include a blank, or nearly blank article, hide the title, and publish it to your front page. Use the hits on that always-published-article to do what you need.
That's exactly what we have on the front page. "Who We Are" which includes a single sentence. The hit count on that article is 0. Other articles on the front page are include in the stock "News" category and get several hundred counts over a period, but the "Who We Are" article doesn't get any counts. Therefore, we have no hit count for the front page.

It's a puzzle.

Phil
Last edited by PhilOSparta on Tue Jan 06, 2009 12:58 pm, edited 1 time in total.

User avatar
GreatGatsby
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 234
Joined: Tue Oct 02, 2007 2:03 pm
Location: Michigan
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by GreatGatsby » Tue Jan 06, 2009 3:49 am

Yeah, after I thought about that for a second, I figured it couldn't work. Joomla only counts hits if you click the article.

I would guess an extension has to do this, right? If not, maybe I can write one. I've been looking for a good challenge for 2009.
Jason Boyette

Hosam Diab
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Tue Feb 19, 2008 12:52 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by Hosam Diab » Tue Jan 06, 2009 4:49 pm

Hi
I've been looking for a good challenge for 2009
Yes it looks very challenging to get an extension to count the hits of the front page alone not all the site's pages and also to display the report in the back end.

But

I looked for an extension to do such good reports all seems to store trier data in the data base so it got big in a few days if the site have a heavy traffic

I'm using Google analytic to collect my site hits and visitors with a single JavaScript code separated from the site database and to not have any load on the site and it gives me all the information that i need to know about my visitors.

Know More About Google anlytic
http://www.google.com/analytics/

My Topic is what i couldn't get from Google is to know what my visitors really read most.

Thanks

User avatar
GreatGatsby
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 234
Joined: Tue Oct 02, 2007 2:03 pm
Location: Michigan
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by GreatGatsby » Tue Jan 06, 2009 5:39 pm

I also use Google Analytics. Here's a couple articles I used to get it working for me:

http://www.goodwebpractices.com/joomla/ ... oomla.html

http://www.goodwebpractices.com/roi/tra ... cally.html
Jason Boyette

mrsfrue
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Mar 10, 2009 8:23 pm

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by mrsfrue » Tue Mar 10, 2009 8:45 pm

Hi,
I am trying to view how many hits I get on the frontpage of my site. I can see hits on all the other pages. I am hoping I've found the right solution here: is this so I will be able to see the number of hits when I log in to the backend, and I'll be able to reset it etc like I can with all the other pages, or will this to put a counter on the actual page?

I am a complete novice but have managed to sort all my problems out so far and with the help of these fab forums, I've come a long way, and not had to post yet, but this has really got me!! :eek:
Anyway! So far, with this issue, I have downloaded and opened the "components/com_content/views/frontpage/tmpl/default_item.php" file, but have no clue what to do with it now! Do I need to paste the following in somewhere:

<?php if ($this->params->get('show_hits')) : ?>
Views :<?php echo $this->item->hits; ?>Times
<?php endif; ?>

Any help would be great!
Thanks

User avatar
PhilOSparta
Joomla! Guru
Joomla! Guru
Posts: 512
Joined: Sun Feb 25, 2007 10:44 pm
Location: New Jersey, USA
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by PhilOSparta » Thu Mar 12, 2009 3:28 pm

mrsfrue wrote: I have downloaded and opened the "components/com_content/views/frontpage/tmpl/default_item.php" file, but have no clue what to do with it now! Do I need to paste the following in somewhere:

<?php if ($this->params->get('show_hits')) : ?>
Views :<?php echo $this->item->hits; ?>Times
<?php endif; ?>
I have determined that all articles have a "hits" field in the database.
The frontpage does NOT have a "hits" field in the database.
Therefore, the code snippet get('show_hits') will not be providing any value whatsoever about the frontpage because no data is available for the frontpage. :(

If we could find a place in the ja_purity/html/ directory that is always traversed during the display of the frontpage, we could possibly implement a template override to provide the frontpage count. I really want a counter that will count even without any articles displayed on the frontpage.

Phil

User avatar
sherif
Joomla! Ace
Joomla! Ace
Posts: 1560
Joined: Fri Jan 12, 2007 12:15 am
Location: Dikirnis , Egypt :: دكرنس ، مصر
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by sherif » Fri Apr 03, 2009 11:46 pm

@Hosam Diab
thanks for the tip , allow me to quote it into arabic

chit107
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Mon Jun 30, 2008 9:52 pm

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by chit107 » Tue May 05, 2009 11:58 am

Is it possible to take the hit counter from article A, and display that count on article B. I know the numbers are in the database, but I do not know how to show article A's count in article B. Any thoughts??

User avatar
revive1
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Sat Apr 12, 2008 1:41 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by revive1 » Sat Jun 13, 2009 4:40 pm

The alternative is to use a plugin that allows PHP in article content... then add this code where ever IN THE CONTENT, you may want the hits to show:

<?php echo '<div class="hits">Hits:' . $article->hits . '</div><br />'; ?>

@chit107,
If you want to display the Hits from Article A within Article you will need to do 3 things:

1) Install a plugin that allows PHP code within your content (We use DirectPHP:)

2) Write down the ARTICLE ID of Article A, which can be found by opening that article, top right hand side.

3) Include this code in ARTICLE B, wherever you want the hits to show, change the div class to whatever you want and style it within your CSS file... don't forget to change the 'XXX's in this code to the Article ID of Article A !!! If you get this wrong, it will error out the page when you try to load it.. if correct, it works like a charm.. we use it one this page:
HERE

Code: Select all

<?php
$db =& JFactory::getDBO();
$db->setQuery("SELECT * FROM #__content WHERE id=XXX");
$rows = $db->loadObjectList();
$r = $rows[0];
$hits = $r->hits;
echo "<div class='hits'>Hits: $hits</div><br />";
?>
My favorite web design/dev tools:
Rackspace Cloud Files + Cloud9 http://cloud9manager.com
24" iMac, MAMP Pro, Logitech MX Revolution, Coda, TextMate, Transmit, Snippley and Adobe CS4
For small ecommerce: http://nanao-cart.com

chit107
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Mon Jun 30, 2008 9:52 pm

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by chit107 » Sat Jun 13, 2009 7:28 pm

Well done! Thanks for the reply.

User avatar
revive1
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Sat Apr 12, 2008 1:41 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by revive1 » Sun Jun 14, 2009 2:10 am

@chit107,

Anytime ;)

More times than not, I find my own answers here in the forums, so anytime I have something little to give back, it's a great thing for me too.. glad the code will work for you..

Cheers
My favorite web design/dev tools:
Rackspace Cloud Files + Cloud9 http://cloud9manager.com
24" iMac, MAMP Pro, Logitech MX Revolution, Coda, TextMate, Transmit, Snippley and Adobe CS4
For small ecommerce: http://nanao-cart.com

scotty_417
Joomla! Apprentice
Joomla! Apprentice
Posts: 39
Joined: Tue Jul 14, 2009 3:58 pm

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by scotty_417 » Thu Jul 16, 2009 9:04 pm

Thanks for the information.
I've downloaded the DirectPHP plugin and enabled it.
I've written down the article number.
I pasted the code that you've listed down below. I tried it both in HTML and directly onto the article itself.
My problem is that after I save, the hits number doesn't show, but the code with the top part chopped off. I've cut and pasted the code in.
Is there something that I'm doing wrong?

Thanks,

Scott

$db =& JFactory::getDBO();
$db->setQuery("SELECT * FROM #__content WHERE id=XXX");
$rows = $db->loadObjectList();
$r = $rows[0];
$hits = $r->hits;
echo "<div class='hits'>Hits: $hits</div><br />";
?>
[/code][/quote]
revive1 wrote:The alternative is to use a plugin that allows PHP in article content... then add this code where ever IN THE CONTENT, you may want the hits to show:

<?php echo '<div class="hits">Hits:' . $article->hits . '</div><br />'; ?>

@chit107,
If you want to display the Hits from Article A within Article you will need to do 3 things:

1) Install a plugin that allows PHP code within your content (We use DirectPHP:)

2) Write down the ARTICLE ID of Article A, which can be found by opening that article, top right hand side.

3) Include this code in ARTICLE B, wherever you want the hits to show, change the div class to whatever you want and style it within your CSS file... don't forget to change the 'XXX's in this code to the Article ID of Article A !!! If you get this wrong, it will error out the page when you try to load it.. if correct, it works like a charm.. we use it one this page:
HERE

Code: Select all

<?php
$db =& JFactory::getDBO();
$db->setQuery("SELECT * FROM #__content WHERE id=XXX");
$rows = $db->loadObjectList();
$r = $rows[0];
$hits = $r->hits;
echo "<div class='hits'>Hits: $hits</div><br />";
?>

User avatar
revive1
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Sat Apr 12, 2008 1:41 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by revive1 » Fri Jul 17, 2009 6:50 am

Where the 'XXX' is in the code.. line 3 on what you've pasted here.. you need to change that to be your article #.. so, for example, if after you enter some content in your article and click apply, you can see the article number at the right of the screen, above the 'parameters' menus.. if the article number is 293, then your 3rd line should look like this:

$db->setQuery("SELECT * FROM #__content WHERE id=293");

Let me know if that helps
:)
My favorite web design/dev tools:
Rackspace Cloud Files + Cloud9 http://cloud9manager.com
24" iMac, MAMP Pro, Logitech MX Revolution, Coda, TextMate, Transmit, Snippley and Adobe CS4
For small ecommerce: http://nanao-cart.com

scotty_417
Joomla! Apprentice
Joomla! Apprentice
Posts: 39
Joined: Tue Jul 14, 2009 3:58 pm

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by scotty_417 » Fri Jul 17, 2009 3:39 pm

Hi, I did get that part and included the article number there.
I can't figure out why, when I paste the code and save, it gets cut off and nothing happens.

I put it in an article.
I tried it on a module that allows me to paste html code (including php).

Same thing happened. Part of it got cut off and nothing happens.

Is there something else I'm missing? It seems relatively straight forward.

User avatar
revive1
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Sat Apr 12, 2008 1:41 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by revive1 » Fri Jul 17, 2009 4:00 pm

Ok, this is a setting in your global config for joomla.. you need to go to your Article Manager, then on the top-right, the New button is a Parameters button.. click it.. scroll to the bottom.. go to Filter Goups.. SELET THEM ALL EXCEPT SUPER ADMIN.. then select Blacklist radio button.. go to the top of the popup and click save.. try pasting your code again..
My favorite web design/dev tools:
Rackspace Cloud Files + Cloud9 http://cloud9manager.com
24" iMac, MAMP Pro, Logitech MX Revolution, Coda, TextMate, Transmit, Snippley and Adobe CS4
For small ecommerce: http://nanao-cart.com

urednik
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 125
Joined: Mon Aug 13, 2007 7:45 am
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by urednik » Sun Jul 19, 2009 10:05 pm

I followed the exact instruction in the first post (including both config. settings), but could not display any hits on my frontpage.
I have newest joomla 1.5 + JaPurity

As usual here I can see hits here (category list): http://www.veneti.info/sl/articles/poljudno-znanstveno
but not in the frontpage!

???
Voluntary history research on Veneti.info

User avatar
revive1
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Sat Apr 12, 2008 1:41 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by revive1 » Mon Jul 20, 2009 4:40 am

Hmm.. not sure about frontpage, there's not a reason that it shouldn't work, BUT, I have not used it on the frontpage (nor do I use the Frontpage menu type most of the time).. Just make sure that your article ID was set correctly in the code, replace the XXX on the 3rd line.. not sure what else to check.. sorry.
My favorite web design/dev tools:
Rackspace Cloud Files + Cloud9 http://cloud9manager.com
24" iMac, MAMP Pro, Logitech MX Revolution, Coda, TextMate, Transmit, Snippley and Adobe CS4
For small ecommerce: http://nanao-cart.com

urednik
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 125
Joined: Mon Aug 13, 2007 7:45 am
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by urednik » Mon Jul 20, 2009 6:28 am

I am talking about the first post, not about the plugin ...
Thanks anyway!
Voluntary history research on Veneti.info

scotty_417
Joomla! Apprentice
Joomla! Apprentice
Posts: 39
Joined: Tue Jul 14, 2009 3:58 pm

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by scotty_417 » Tue Jul 21, 2009 3:39 pm

Thanks a lot for all your help.
Worked like a charm.

little_brain
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Fri Apr 03, 2009 9:33 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by little_brain » Wed Sep 30, 2009 12:48 pm

I've followed the instructions above and am seeing the hit counter on the front page. However the counter does not update when the front page is visited. GreatGatsby (above) seemed to think this is a fundamental limit in Joomla.

Has anybody found a solution to this problem? I tried using the "Show Hits Anywhere" module but sadly it doesn't show on the front page!. And it doesn't update when you refresh a category blog page. So it doesn't seem any different to the built-in hit counters.

heroskiller
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Jan 20, 2010 8:56 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by heroskiller » Wed Jan 20, 2010 8:59 am

O great! Work!

Thanks!

jayfonseca.com

heroskiller
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Jan 20, 2010 8:56 am

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by heroskiller » Mon Jan 25, 2010 3:53 am

And dont forget on global option, on your front page name, mainmenu, check "Show Hits"

jesusrodriguezgarcia.com

jayfonseca.com

Show my hits on front page!

Thanks!

User avatar
PhilOSparta
Joomla! Guru
Joomla! Guru
Posts: 512
Joined: Sun Feb 25, 2007 10:44 pm
Location: New Jersey, USA
Contact:

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by PhilOSparta » Mon Jan 25, 2010 5:39 pm

little_brain wrote:I've followed the instructions above and am seeing the hit counter on the front page. However the counter does not update when the front page is visited. GreatGatsby (above) seemed to think this is a fundamental limit in Joomla.

Has anybody found a solution to this problem? I tried using the "Show Hits Anywhere" module but sadly it doesn't show on the front page!. And it doesn't update when you refresh a category blog page. So it doesn't seem any different to the built-in hit counters.
After extensive testing on this problem, I believe that the actual code that increments the hit counter in each article is only activated if the article is accessed by a menu link or directly to its URL. If the article is within a blog layout it's counter is not incremented. The "Show Hits Anywhere" module only shows the hits attributed to a single article if that article appears on its own page.
It appears that there is currently no accurate way to get the hit counts for any particular page if it is viewed within a blog layout. If the frontpage is accessed as an article and not a blog, the hit counters work for the front page article.

I'm still searching for a good hit counter.

Phil

User avatar
jigster
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Mar 21, 2011 1:42 pm

Re: Show Hits Any Where ( Frontpage - Category - Article )

Post by jigster » Mon Mar 21, 2011 2:04 pm

I thought i should register and share my update to this issue. I've used the php code from this thread and expanded it to advance hits by one when the page is accessed resolving the problem of hits not registering when people view the frontpage. As before XXX relates to the Article ID number. It seems to work ok for me, maybe others will find this useful. :)

<?php
$db =& JFactory::getDBO();
$db->setQuery("SELECT * FROM #__content WHERE id=XXX");
$rows = $db->loadObjectList();
$r = $rows[0];
$hits = $r->hits;
$hits++;
$query = "UPDATE #__content SET hits = $hits WHERE id=XXX";
$db->setQuery( $query );
$db->query();
echo "<div class='hits'>Hits: $hits</div><br />";
?>


Locked

Return to “Administration 1.5”