- Posts: 3
COMMUNITY FORUM
Hits counter when using Jotcache
- dennisb
-
Topic Author
- Offline
- New Member
I'm looking for a solution to use full page caching (jotcache), but still counting and display the total hits.
When I activate the jotcache full page caching, the number of hits will only count up once in a while when the page cache is expired and have to be recached.
for normal Joomla! articles, I found a good solution, described in the topic below:
Joomla forum hits counter with full page cache
Is there a way to implement this solution for K2 items?
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- dennisb
-
Topic Author
- Offline
- New Member
- Posts: 3
Yes I know that the amount of hits is to provide a general image of the item popularity, but it looks strange when a webpage has serveral thousands hits, a main article only showed up 62 hits.
I think there are more people with this problem, and looking for a solution.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if (isset($_GET['view']) && strtolower($_GET['view']) == 'item') {
$articleId = (int) $_GET['id'];
$db = JFactory::getDBO();
$db->setQuery(
'UPDATE #__k2_items' .
' SET hits = hits + 1' .
' WHERE id = '.(int) $articleId
);
$db->query();
}
?>
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- dennisb
-
Topic Author
- Offline
- New Member
- Posts: 3
This worked for me!
I installed a custom code module.
insert this code and exclude this module position from being cached.
Now every time the k2 item page is recached, the new hits are displayed correct.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Marcos
-
- Offline
- New Member
- Posts: 1
Thank you!
Please Log in or Create an account to join the conversation.
- Petar
-
- Offline
- New Member
- Posts: 18
I try Blank module and Flexi custum code, put code you write above, exclude position in Jotcache, But does not work
Please help
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
I cannot know why this does not work. I was just asked to provide some code. I don't even know how Jotcache works. K2 includes also a module for custom code. Try to use that.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Petar
-
- Offline
- New Member
- Posts: 18
I try with K2 tools custum code. Put this code in module, set module to desidered position, excluded this position from caching, but no result. Hit are not increased by +1
Is code good. I have latest K2 and latest joomla 3.3
Big Thnx
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Andi Setyaji
-
- Offline
- New Member
- Posts: 2
May I ask, where the code is entered?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
More information on overrides can be found here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Andi Setyaji
-
- Offline
- New Member
- Posts: 2
My regards,
Andi
Please Log in or Create an account to join the conversation.
- Martin
-
- Offline
- New Member
- Posts: 1
i read the answers thoughtfully but it doesn't work.
I copied the code into the K2 Tools module, php execution setted to yes. Module is published and has a position. Then i have activated the Joomla cache (normal) and the hit counter comes to a halt.
Please Log in or Create an account to join the conversation.
- Alexandros Androutsos
-
- Offline
- New Member
- Posts: 12
Krikor wrote: In the item.php.
More information on overrides can be found here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Dear mr Krikor
The whole topic is a bit vague
It seems that K2 hits counter is not working when using joomla cache. Is there a simple, step by step way to actually make it workng?
if you say "add the code in item.php" then you just don't know what to do!
I need the information to provide popular items lists and similar statistics in my site.
I tried to use the code below
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if (isset($_GET['view']) && strtolower($_GET['view']) == 'article') {
$articleId = (int) $_GET['id'];
$db = JFactory::getDBO();
$db->setQuery(
'UPDATE #__content' .
' SET hits = hits + 1' .
' WHERE id = '.(int) $articleId
);
$db->query();
}
?>
in item.php but no luck. Please since it seems that this is an issue that has been haunting K2 for some time now, could you please help us solve it by providing a step-by-step instruction set?
if that includes adding jotcache, I don't mind, however at the moment jotcache is not installed on my website. (www.coffeespots.gr)
Thank you.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Alexandros Androutsos
-
- Offline
- New Member
- Posts: 12
Krikor wrote: Since I do not know what to do, you can read the thread from the start, or you can try to be more polite.
Dear mr. Krikor
I was not trying to be rude.
Let me take my reply step by step:
I certainly did not mean that it's a bit vague because of you. I just pointed out that posts in this topic (which I've read from the beginning) do not cover in full the steps that need to be taken in order to get to a solutionThe whole topic is a bit vague
mmm... I guess you are right to be offended by that. However I did not really mean that "you" mr. Krikor do not know stuff. I suppose the sentence sounded better in my head but my english make it sound a bit rude and point you out as the one to blame. Please accept my apologies for that and let me rephrase:if you say "add the code in item.php" then you just don't know what to do!
if you say "add the code in item.php" then the person who tries to follow that instruction just won't know what to do!
Do you mind helping out in implementing that?
I any case I did not mean to insult you. I just figured that you seem like one who actually could easily provide a simple solution for "the counter not updating with cache turned on" issue.
Please accept my apologies again and if you could help out, I'd appreciate your feedback.
Otherwise let it all be well and once I've figured it out, I will post it here and urge the developers to add the update to the next version.
P.S. Joomla core article system's hit counter is not affected by cache.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The code should be pasted on a K2 Tools Module.
PHP parsing must be enabled.
Finally this module should NOT be cached. Disable caching from the module's params and if Jotcache offers an additional caching layer, exclude it from there as well.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Alexandros Androutsos
-
- Offline
- New Member
- Posts: 12
Or just the menu items for each K2 category?
Please Log in or Create an account to join the conversation.