TIP: Show all categories at the same level as current category

I had the need to show all categories at the same level of the current categories and thought it might be helpful to someone else so heres the tip.



Example: If the customer is browsing Apparel category and clicks Shirts there are no more sub categories under Shirts but they might want to go to another sub category of Apparel. This tip makes it possible to provide this information to the customer via links or whatever you prefer.



create file addons//my_changes/controllers/customer/categories.post.php and this code:

```php

if ($mode == 'view') {
$sub_categories = $view->get_var('subcategories');
$category_id = $view->get_var('$category_data');
$category_data = $view->get_var('category_data');

if (! $sub_categories)
{
$subcat = $view->get_var('subcategories');

$subcat = fn_get_subcategories($category_data[parent_id]);
foreach($subcat as $k => $v) {
$subcat[$k]['main_pair'] = fn_get_image_pairs($v['category_id'], 'category', 'M', true, true);
}
$view->assign('parent_subcategories', $subcat);
}
}
?>

```



now from within any template file you can refer to the variable parent_subcategories and use something like this to loop through the categories.




{if $subcategories}
{foreach from=$parent_subcategories item="subcategory"}
{$subcategory.category} 

{/foreach}
{/if}