Thursday, 23 July 2015 21:14

K2 Links for JCE plugin

As many others, K2 has it's own extension to be added to great JCE Editor for Joomla. In case you downloaded plugin from it's official developer's git: https://github.com/joomlaworks/K2-Links-for-JCE, you might notice that link you create does not provide Itemid for either K2 item or category if it exists. We needed this to work properly, since almost all of our K2 stuff has it's place in menu. I believe this is the case with most of you, too.

Here's what you have to do in order to "hook" link to propper menu item if it exists:

1. When propperly installed, this plugin is located in \components\com_jce\editor\extensions\links. There's folder "k2links". Open it and open file k2.php.

 

2. Line 181 is:

$item->href = K2HelperRoute::getItemRoute($item->id.':'.$item->alias, $item->catid);

Put comment sign in front of that line "//" (or delete it)

 

3. Just below mentioned line add following code:

$db = JFactory::getDBO();
$query = 'SELECT catid FROM #__k2_items WHERE id ='.$item->id.' AND published = 1';
$db->setQuery($query);
$item->catid = $db->loadResult();
$query = 'SELECT alias FROM #__k2_categories WHERE id ='.$item->catid;
$db->setQuery($query);
$item->catalias = $db->loadResult();
$item->href = K2HelperRoute::getItemRoute($item->id.':'.$item->alias, $item->catid.':'.urlencode($item->catalias));

 This should solve your problem now.

 

Read 1581 times Last modified on Thursday, 27 August 2015 13:07
Login to post comments