Additional Categories for K2

>> Installation

Additional Categories for K2 comes in one unified installer for Joomla! versions 1.5, 2.5 & 3.0. After you download the zip file upload and install the component by using the Joomla! installer. Navigate to:

Extensions >> Install/Uninstall (for Joomla! 1.5) or
Extensions >> Extension Manager (for Joomla! 2.5 or newer)

...to install the component.

With the Additional Categories for K2 component a K2 plugin installed also containing all the core functionalities of the Additional Categories for K2 package. Do not mind publish it as it is already published by the installer of the component.

>> Using Additional Categories for K2

Additional Categories for K2

The interface of Additional Categories for K2 exists at the content tab of any k2 item. With the multiple select box ,that contains all the current K2 categories , you can assign the item you are currently edit or create to 1 or more additional K2 categories . This item will be displayed now at frontend not only to the category defined by K2 but also at the additional categories assigned by the Additional Categories for K2 extension. Additional Categories for K2 stands as a layer , when K2 lists the category items, and returns the data needed, to display the extra K2 items. In order to avoid any conflicts there is no interfere with the default K2 category assignment procedure neither any core functionality of the K2 component.

>> Uninstall

Simply navigate to

Extensions >> Install/Uninstall >> Components (for Joomla! 1.5) or
Extensions >> Extension Manager >> Manage (for Joomla! 2.5 or newer)

Locate the additional categories extension select it by clicking next to it and press uninstall from the toolbar menu.

>> Extend the functionalities

The sections below describes some functionalities that may concern you. Unforunately there is no trigger from K2 in order for the plugin to intercept and execute these functionalities. The good news is that Additional Categories for K2 plugin has already include these functions to do those tasks and the only thing that is missing is the plugin call. With a little effort from you these can be achieved.

As new versions of K2 are released from time to time new lines of code are added, modified or removed at the core K2 files. You may have as well modified the core K2 files for your own needs. As you understand there may be a little confusion with the line numbers listed at the modifications below. It is advisable to have as a guide the attached files at every section in order to understand better the position that the code must be applied.

It must be noted that hacking core files of K2 or any other extension is not an ideal solution. Create a backup of your old files and be very cautious when you apply the modifications listed below.

Here are some additional resources you may want to check out concerning hacking core files.

1) Frontend Subcategories Count items is wrong

If you have in Category view options of K2, the option Item counter(next to sub-category title) selected on show value then you will notice at frontend that the count number of the subcategory (Children categories ) counts wrong, if there are items that were added to this subcategory from Additional Categories for K2 plugin. In order to achieve the right count number a little hack must be done in the K2 source code.

Open {site root} components/com_k2/models/itemlist.php and locate this line (Line 701):

 return $total;

Add these lines exactly above before the return statement

$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin ('k2');
$dispatcher->trigger('onK2BeforeSetCountCategoryQuery', array(&$total, &$id, &$categories));

Attached below you will find the modified file ( components/com_k2/models/itemlist.php ) in order to compare it with yours or in case you are confused about the position the above code should be placed. Search for /** K2 Additional Categories **/ at the downloaded file to find the position more quickly. It is advisable not to replace this file with yours as it is provided only as a guide.

This code above trigger the function of the plugin and the counting now must be correct . The cons of this procedure is that this hack, is at the core files of k2,so every time you are updating K2 component this modification is overrided and no longer exists.

2) Frontend K2 item Published in shows only the main category and not the additionals

If you have the option Category to show value ( Item view options in category listings or Item view options) then you will notice that only the main category defined from k2 is shown as link at published in. Again we must made a modification in order to insert the plugin trigger.The good news with this procedure is that this modification will be on template files means that there is no override if a k2 update occurs. Of course presupposes that is not the default template of k2.

Open {site root} components/com_k2/templates/ {your_tamplate_folder} / category_item.php and locate these lines:

<span><?php echo JText::_('K2_PUBLISHED_IN'); ?></span>
			<a href="<?php echo $this->item->category->link; ?>"><?php echo $this->item->category->name; ?></a>

Add these lines exactly below

	
            <?php
			  $dispatcher = JDispatcher::getInstance();
			  JPluginHelper::importPlugin ('k2');
			  $additional_category_links=$dispatcher->trigger('onK2AfterLinkCategoryPublish', array($this->item->id));
			  echo $additional_category_links[0];
            ?>

Now the items at the category list must show not only the main category defined by k2 but also the categories defined by Additional Categories for K2.

The same issue occurs also at the item view . The procedure is the same

Open {site root} components/com_k2/templates/ {your_tamplate_folder} / item.php and locate these lines:

<span><?php echo JText::_('K2_PUBLISHED_IN'); ?></span>
			<a href="<?php echo $this->item->category->link; ?>"><?php echo $this->item->category->name; ?></a>

Add these lines exactly below

	
            <?php
			  $dispatcher = JDispatcher::getInstance();
			  JPluginHelper::importPlugin ('k2');
			  $additional_category_links=$dispatcher->trigger('onK2AfterLinkCategoryPublish', array($this->item->id));
			  echo $additional_category_links[0];
            ?>

Attached below you will find the modified template files in order to compare them with yours or in case you are confused about the position the above code should be placed. Search for <!-- K2 Additional Categories --> at the downloaded files to find the position more quickly. It is advisable not to replace these files with yours as they are provided only as guides.

3) Backend categories Count items is wrong v1.0.0 ( not recommended )

A slow performance has been noticed at sites with a high number of K2 categories during the category listing at administrator panel. It is strongly recommended that you update Additional Categories for K2 at version 1.0.1 and follow the instructions listed in section 3.a.

At backend K2 >> categories the Active or Trashed items count is wrong if this category containing items defined by the Additional Categories for K2. The count number reflects only the total of items defined by K2 and not by Additional Categories for K2 plugin. So in order to change this a modification need to be done in order to trigger the function of the Additional Categories for K2 plugin.

Open {site root} administrator/components/com_k2/models/category.php and locate this line (Line 149):

$query = "SELECT COUNT(*) FROM #__k2_items WHERE catid={$catid} AND trash = ".(int)$trash;

Add these lines exactly below

$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin ('k2');
$additional_category_links=$dispatcher->trigger('onK2BeforeCountCategoryItemsQuery', array(&$query));

Attached below you will find the modified file ( administrator/components/com_k2/models/category.php ) in order to compare it with yours or in case you are confused about the position the above code should be placed. Search for /** K2 Additional Categories **/ at the downloaded file to find the position more quickly. It is advisable not to replace this file with yours as it is provided only as a quide.

This code above trigger the function of the plugin and the counting now must be correct. The cons of this procedure is that this hack, is at the core files of k2,so every time you are updating K2 component this modification is overrided and no longer exists.

3.a) Backend categories Count items is wrong v1.0.1 ( recommended )

The functionality remains the same as section 3 but the procedure is now optimized. You must have Additional Categories for K2 v1.0.1 installed in order to use this option.

Open {site root} administrator/components/com_k2/models/category.php and locate these lines (Line 165):

$query = "SELECT COUNT(*) FROM #__k2_items WHERE catid={$catid} AND trash = ".(int)$trash;
$db->setQuery($query);
$result = $db->loadResult();

Add these lines exactly below

$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin ('k2');
$additional_category_links=$dispatcher->trigger('onK2BeforeCountCategoryItemsAdmin', array(&$result,$catid,$trash));

Attached below you will find the modified file ( administrator/components/com_k2/models/category.php ) in order to compare it with yours or in case you are confused about the position the above code should be placed. Search for /** K2 Additional Categories **/ at the downloaded file to find the position more quickly. It is advisable not to replace this file with yours as it is provided only as a quide.

4) When an item removed from k2 the entry at #__k2_additional_categories table does not.

This has no interfere with the functionalities of Additional Categories for K2 plugin neither the display of the frotend or backend items of k2.The itemID may remains in the database but it will never requested as the K2 item id is removed from the K2 database tables. But i and many others of course do not want to have garbage data in our databases. As with the other functionalities on this documentation there must be a modification on the source code of k2 in order to to trigger the function of the Additional Categories plugin.

Open {site root} administrator/components/com_k2/models/items.php and locate this line (Line 706):

$dispatcher->trigger('onFinderAfterDelete', array('com_k2.item', $row));

Add these lines exactly below :

JPluginHelper::importPlugin ('k2');
$dispatcher->trigger('onK2AfterDeleteItem', array($row));

Attached below you will find the modified file ( administrator/components/com_k2/models/items.php ) in order to compare it with yours or in case you are confused about the position the above code should be placed. Search for /** K2 Additional Categories **/ at the downloaded file to find the position more quickly. It is advisable not to replace this file with yours as it is provided only as a quide.

This code above trigger the function of the plugin and now the item deleted as well from the Additional Categories for K2 database table. The cons of this procedure is that this hack, is at the core files of k2,so every time you are updating K2 component this modification is overrided and no longer exists.

Last modified on Monday, 22 April 2013 15:25
Copyright © 2011 - 2012 netpin.gr. All rights reserved.
Joomla! is a registered trademark of Open Source Matters, netpin.gr is not affiliated with or endorsed by Open Source Matters or the Joomla! Project.The Joomla! logo is used under a limited license granted by Open Source Matters, the trademark holder in the United States and other countries.