1

As mentioned in the title, I'd like to know how to call the K2 current item's title & creation date in my template's index.php.

What I'm trying to achieve is to display (if the user is on a K2 item's page ) the title and creation date of a K2 item somewhere else ( in the index.php of my template for example).

The thing is that I'd like to completely move the title/created date from K2 items to a module position on my template.

I've done a lot of researches but couldn't find anything but this, that works well, but only for Joomla article's titles, not K2's:

$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $article->load($article_id);
    echo $article->get("title");
}

Thanks in advance!

1

You can do something similar like:

$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 $item->title;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.