get the current k2 item ID

3.6k views Asked by At

I want to get the current item id from k2 and store it to a cookie.
(Of course when i wrote "the current item" I am in the item view of my k2 template.)

How can I get the item ID from K2?

I tried $this->item->id but seems it's not working.

Any ideas?
Thanks!

3

There are 3 answers

0
Shaz On

It depends where you are. Is it an item view ? If so, $this->item->id should work. I've done it many times.

0
meta morpher On
$K2Itemid = JRequest::getInt('id');
$db = JFactory::getDBO();
$db->setQuery("SELECT title FROM #__k2_items WHERE id = ".$K2Itemid );
$K2Catid = $db->loadResult(); 
echo $K2Catid;
0
Joseph On

I agree with @shaz - this worked for me (item.php and category_item.php overrides):

<?php echo $this->item->id; ?>