I am in a big trouble. I have been using ajax to fetch k2 item and display it on my page. On my page there are both k2 category list and article area, when one of the items in the category is clicked, I prevent default link and use ajax to fetch k2 item content(by adding '&format=json' to the url) to display in the article area. I just realized this way the item won't be considered viewed, thus item.hits will remain 0. I have been spending too much time on the layout to change it, so I think my best bet is to find out how k2 item calculate how many times it has been viewed, and maybe there is some trick to force it.
1 Answer
In K2, articles are represented by K2ModelItem (com_k2/models/item.php, line 892), where you can find:
function hit($id)
{
$row = JTable::getInstance('K2Item', 'Table');
$row->hit($id);
}
If you are fetching items directly from tables, then it is not consistent with K2 model. It would be better to follow the general MVC pattern and access them via K2ModelItem... or just increment hits calling in the same way than model works.
-
Thank you very much Sir for the hint. I have read the
item.php
file. I guess this function is to increment item's hits property, is it right? I am thinking if I am to keep my ajax layout, I will have to write some PHP code to manually call this function. To do that, I need to know more about how k2 functions: Originally, when is this function called? Is it when the users click relative link or when some contents get displayed? Thank you very much again– shenkwenCommented Aug 17, 2015 at 14:09 -
-
What exactly can be considered "shown". Apparently, by fecthing the item content and display them is not considered "shown". By the way, to better demonstrate the problem, the live page is here:aoafinc.org/…. It is underdeveloped and mostly in Chinese, but you get the idea. And I have posted a new SO question here:stackoverflow.com/questions/32054153/…. You can move there if you want.– shenkwenCommented Aug 17, 2015 at 15:30