It is great that k2 supports ajax. Although I have been using k2 for years, I just realized it by reading this blog post: http://getk2.org/blog/786-k2-v257-released-introduces-json-jsonp-content-output and started using ajax to improve my k2 powered websites.
But I have had a problem.
On my page there are both item list from categories and a k2 content module showing the lasted item. I have made it so that when one of the items in the category is clicked, the item content in the module gets updated by ajax. Live page is here, aoafinc.org/index.php?option=com_k2&view=itemlist&layout=category&task=category&id=2&Itemid=150&lang=en-us It is under developed and mostly Chinese, but you get the idea.
It seems good but the problem is, the item hits won't increase. ( I had to use some javascript to fake the item hits number displayed under the title for now ) Is there anyway to solve this? I am thinking maybe I need to hardcode some PHP file so that every time the 'url+&format=json' gets displayed, item hits increases.
Someone has pointed out that there is this function
function hit($id)
{
$row = JTable::getInstance('K2Item', 'Table');
$row->hit($id);
}
in com_k2/models/item.php.
But I really know very little about k2 core and don't know what to do with it, so any direction or hints will be greatly appreciated!
And in some way, I think this is a more general issue than just joomla and k2. If you use ajax to fetch content, how do you make it count for the content hits?
under com_k2/views/item, there are view.html.php
and view.json.php
, in view.html.php
line 134
// Increase hits counter
$model->hit($item->id);
while view.json.php
doesn't have this line. By adding this line to it, problem is solved!