There are 2 categories with n-th number of sub-categories in each. I deduce in one place one category, then the second. I deduce like this

<div class="side_category_wrapper<?php echo $module; ?>"> <ul class="sc"> <?php foreach($categories as $category) { for($i=0 ; $i<count($category['children']) ; $i++) {?> <li><a href="<?php echo $category['children'][$i]['href']?>" class="sc_item"><?php echo $category['children'][$i]['name']?></a></li> <?php } ?> <?php } ?> </ul> </div> 

But this way I display all subcategories at once. How do I display subcategories that fall into a specific category?

    2 answers 2

    There are $category['category_id'] (categories id) and $child['category_id'] (id subcategories) added category_id' => $category['category_id'] to controller:

     $this->data['categories'][] = array( 'name' => $category['name'], 'children' => $children_data, 'category_id' => $category['category_id'], 'column' => $category['column'] ? $category['column'] : 1, 'href' => $this->url->link('product/category', 'path=' . $category['category_id']) ); 

    and with the aid of crutches, I filtered everything. Thanks for the help!

      I understand you take from the database data ?? You can try nested sets, just you will be able to display a tree structure of your categories !!!

      • Thanks for the answer, but I would like to see an example of implementation. I am a beginner ... - zey_ser
      • one
        A lot of information about this has Google! Here there is a good post on habr: habrahabr.ru/post/153861 and here is a library for working with a tree structure: github.com/kvf77/DbTree - LevBazdyrev
      • Try to write more detailed answers. You can include sample code, explain the solution path, point out specific errors, etc. - Athari