Keyword

[SOLVED] Hide empty categories in k2 Tools module (cat. menu)

  • KE Communication
  • KE Communication's Avatar Topic Author
  • Offline
  • New Member
More
9 years 1 month ago #146803 by KE Communication
How can I make it that only categories with published items show up in the Module (cat. menu list version)?

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

More
9 years 1 month ago #146809 by Lefteris
The module only checks for the publishing status of the categories. If you want to hide a category just unpublish it.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Rupert Griffiths
  • Rupert Griffiths's Avatar
  • Offline
  • Junior Member
More
8 years 11 months ago #148364 by Rupert Griffiths
Replied by Rupert Griffiths on topic Hide empty categories in k2 Tools module (cat. menu)
I managed to do this.

About line 550 - 570 in root/modules/mod_k2_tools/helper.php.

Change

foreach ($rows as $row)
{
if ($params->get('categoriesListItemsCounter'))
{
$row->numOfItems = ' ('.modK2ToolsHelper::countCategoryItems($row->id).')';
}
else
{
$row->numOfItems = '';
}

if (($option == 'com_k2') && ($view == 'itemlist') && ($catid == $row->id))
{
$active = ' class="activeCategory"';
}
else
{
$active = '';
}

if (modK2ToolsHelper::hasChildren($row->id))


CHANGE TO


foreach ($rows as $row)
{
if ($params->get('categoriesListItemsCounter'))
{
$itemnumber = modK2ToolsHelper::countCategoryItems($row->id);
}



if ($itemnumber==0)
{
$active = ' class="hidden"';
}
else
{
$active = '';
}




if (modK2ToolsHelper::hasChildren($row->id))

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 11 months ago #148403 by Krikor Boghossian
Replied by Krikor Boghossian on topic Hide empty categories in k2 Tools module (cat. menu)
Rupert keep a backup of this edit (or the URL of the thread in this case) because you will need to reapply it when you update K2.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Rupert Griffiths
  • Rupert Griffiths's Avatar
  • Offline
  • Junior Member
More
8 years 11 months ago - 8 years 11 months ago #148423 by Rupert Griffiths
Replied by Rupert Griffiths on topic Hide empty categories in k2 Tools module (cat. menu)
Yes I will thanks. Updates are not too frequent ;p

Here is improved replacement code - to keep the "active" class for active categories:
foreach ($rows as $row)
			{
				if ($params->get('categoriesListItemsCounter'))
				{
					$itemnumber = modK2ToolsHelper::countCategoryItems($row->id);
				}
			
				if ($itemnumber==0)
				{
					$active = ' class="hidden"';
				}
				else
				{
					if (($option == 'com_k2') && ($view == 'itemlist') && ($catid == $row->id))
				{
					$active = ' class="activeCategory"';
					}
					else
					{
					$active = '';
					}
				}

				if (modK2ToolsHelper::hasChildren($row->id))
Last edit: 8 years 11 months ago by Krikor Boghossian.

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


Powered by Kunena Forum