Улучшаем модуль Категории для Joomla 3 часть 2

Several days ago I made some improvements in module mod_articles_categories - now it shows in tree only selected in admin panel categories.  But after that I got new "call"- all categories in module tree we always opened, but I wanted to show only parent categories and when parent category is active, only at that moment show it`s children categories tree. So I decided to make this standard Joomla Categories module better again. 

Category tree in this module looks like "looping" function. It looks for category $item in object $list, but then $item has child categories , function saves list of child categories in new object $list and onfly changes old $list with new, old $list is saved in $tmp variable waiting new foreach cirle. Well how it works and looks like I`l show below. 

Улучшаем модуль Категории для Joomla 3 часть 2

Let`s get active category ID from Joomla 3 engine input, new string number 17:

$bc     = $params->get('catid');

I like active category be highlighted, so I changed it style a little bit, in my example it`s black:

 <a <?php if ($id == $item->id && $view == 'category' && $option == 'com_content' or $cid == $item->id && $view == 'article') echo 'style="color: #fff; background: #000; left: 3px; text-decoration: none"'; ?> href="/<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->id)); ?>">

I had to use one new "foreach" circle before "looping", so I wrote new strings 32,33,34:

 <?php $children = $item->getChildren(); ?>
<?php foreach ($children as $child) : ?>
<?php if ($id == $item->id || $id == $child->id || $cid == $child->id) : ?>

Closing new foreach and if operators, 45 string number:

<?php endif; ?><?php endforeach; ?>

 As usual, you can download edited files here:

Download file mod_articles_categories-v2.zip (6kb)
Already downloaded 15 times

Copy first file default_items.php from downloaded archieve to  templates/YOUR_TEMPLATE/html/mod_articles_categories/, and copy second file mod_articles_categories.xml in  /modules/mod_articles_categories/. Thats all, good luck laughing

 

If you like this - share it with your friends. That would be the best "donation" for me!

If you want to ask question or comment - login by using your favourite social network

Add comment