Show images for the sub-categories in the opencart version 2.3
Find following code at catalog\controller\product\category.php
1 2 3 4 | $data['categories'][] = array( 'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url) ); |
Replace the code with below code:
1 2 3 4 5 | $data['categories'][] = array( 'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), 'image' => $this->model_tool_image->resize($result['image'], 100,100), 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url) ); |
Changed is ‘image’ => $this->model_tool_image->resize($result[‘image’], 100,100), if you have to increase the size then change 100 to other values.
Find following code at catalog\view\theme\default\template\product\category.tpl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?php if ($categories) { ?> <h3><?php echo $text_refine; ?></h3> <?php if (count($categories) <= 5) { ?> <div class="row"> <div class="col-sm-3"> <ul> <?php foreach ($categories as $category) { ?> <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li> <?php } ?> </ul> </div> </div> <?php } else { ?> <div class="row"> <?php foreach (array_chunk($categories, ceil(count($categories) / 4)) as $categories) { ?> <div class="col-sm-3"> <ul> <?php foreach ($categories as $category) { ?> <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li> <?php } ?> </ul> </div> <?php } ?> </div> <?php } ?> <?php } ?> |
Replace with the below code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?php if ($categories) { ?> <h3><?php echo $text_refine; ?></h3> <?php if (count($categories) <= 5) { ?> <div class="row"> <div class="col-sm-3"> <ul> <?php foreach ($categories as $category) { ?> <li> <a href="<?php echo $category['href']; ?>"> <?php if($category['image']){ ?> <img src="<?php echo $category['image']; ?>" ><br> <?php } ?> <?php echo $category['name']; ?></a></li> <?php } ?> </ul> </div> </div> <?php } else { ?> <div class="row"> <?php foreach (array_chunk($categories, ceil(count($categories) / 4)) as $categories) { ?> <div class="col-sm-3"> <ul> <?php foreach ($categories as $category) { ?> <li><a href="<?php echo $category['href']; ?>"> <?php if($category['image']){ ?> <img src="<?php echo $category['image']; ?>" ><br> <?php } ?> <?php echo $category['name']; ?></a></li> <?php } ?> </ul> </div> <?php } ?> </div> <?php } ?> <?php } ?> |
Extra code added is below and there are two places to add the code:
1 2 3 | <?php if($category['image']){ ?> <img src="<?php echo $category['image']; ?>" ><br> <?php } ?> |
You are set for the default theme, but if you are using custom theme then you have to manage as per your theme.
2 Comments
Pingback: Show images for the sub-categories in the opencart version 1.5+ - Webocreation
computer speakers review
Just want to say your article is as surprising.
The clearness on your submit is just spectacular and that
i can assume you’re a professional on this subject.
Fine with your permission let me to grab your RSS feed to
stay updated with impending post. Thanks a million and please continue
the rewarding work.