Keyword

How to Show K2 Item Tag List in Template's index.php

More
2 years 8 months ago #179337 by Leena
I need to get the tag list of a K2 item and display it in a position in my template's index.php.

Pasting the code below in index.php allows me to retrieve's the K2 item's title:

$app = JFactory::getApplication();
$jinput = $app->input; 
$option = $jinput->getCmd('option');
$view = $jinput->getCmd('view');

if ($option=="com_k2" && $view=="item") 
{
    $item_id = $jinput->getInt('id');

    JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables');
    $item = JTable::getInstance('K2Item', 'Table', array());
    $item->load($item_id);

    echo "<p>" . $item->title . "</p>";
}

How can I tweak this to get the item's tag list instead?

Thank you!

I think a possible answer is here:  Custom K2 Content Module Assistance - Page 2 - Community Forum - JoomlaWorks , but the code won't show so I'm not sure what to do.

Please Log in or Create an account to join the conversation.

More
2 years 8 months ago #179344 by Goble002
If you don't have many items, you can load K2 content module and configure the tags there.

If you have many items, you can use the related k2 module from Raxo.org

Please Log in or Create an account to join the conversation.

More
2 years 8 months ago #179360 by Leena
If anyone is looking for a way to do this, I found the below code works:

$app    = JFactory::getApplication();
$jinput = $app->input; 
$option = $jinput->getCmd('option');
$view   = $jinput->getCmd('view');

if ($option =="com_k2" && $view=="item")  {
    JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables');
    $item = JTable::getInstance('K2Item', 'Table', array());
    $item->load($item_id);

    $tags = K2ModelItem::getItemTags($item_id);
    foreach ($tags as $tag) {
       echo $tag->name;
    }
}

 

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum