Tuesday, 13 December 2016 08:57

K2 Links for JCE (v2.6.0+) plugin

We already wrote about this issue with K2 plugin for JCE editor. This is just an update of the same article, since JCE developer changed it's code and now all JCE plugins are actually installed as regular Joomla plugins, not JCE addons anymore. This started with version 2.6.0 of JCE and all future versions will act this way. So the only thing that changed here is location of the file you need to edit. Please read all that follows to correct links you make using JCE and K2 plugin for JCE.

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 /plugins/jce/links-k2/k2links. There's file k2.php. Open it to edit.

 

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 471 times Last modified on Tuesday, 13 December 2016 09:08
Login to post comments