Search code examples
opencartopencart2.x

Show all Category & Sub- Category in a particular page like as sitemap


I am New to opencart. I Just want to show all Category & Sub- Category in a

particular page like as sitemap, Which is liked by my Boss.


Solution

  • Check out this code. Just paste it in your desired controller.

    $data['categories'] = array();
    
    $categories = $this->model_catalog_category->getCategories(0);
    
    foreach ($categories as $category) {
        echo $category['name'] . '<br/>';
        $children_data = array();
        $children = $this->model_catalog_category->getCategories($category['category_id']);
    
        foreach ($children as $child) {
            echo ' --- ' . $child['name'] . '<br/>';
        }
    }