add code on specific category id opencart 2.3.0.2

185 Views Asked by At

I want to add a image with a link on a specific category id but can't seem to work out how to do it in category.tpl file, below is what I have but nothing is showing on the category

<?php if($category_id=="1697") { ?>
        <a href="#"><img alt="Seagate Barracuda SSD's" class="img-responsive" src="image/catalog/Seagate-Barracuda-SSDs.jpg" /></a>
    <?php } ?>

I am using seo urls but thought as it's the category id, it would show or is there something I need to add into the catalog.php controller file?

Update: Just managed to solve it with the following code

In catalog/controller/product/catalog.php, added the following in

$data['category_id'] = $category_id;

In catalog/view/theme/default/product/catalog.tpl, I got the following

<?php if ($category_id == '1697') { ?>
       <a href="#"><img alt="Seagate Barracuda SSD's" class="img-responsive" src="image/catalog/Seagate-Barracuda-SSDs.jpg" /></a>
    <?php } ?>
1

There are 1 best solutions below

0
On

First in the default OC in folder catalog/view/theme/default/product file catalog.tpl does not exist and catalog.php in the corresponding controller folder also does not exist.

Maybe you want to retrieve in catalog/view/theme/default/product/category.tpl? So if you want to retrieve category_id in catalog/view/theme/default/product/category.tpl you should:

in catalog/controller/product/category.php find:

$category_info = $this->model_catalog_category->getCategory($category_id);

belowe add:

$data['category_id'] = $category_info['category_id'];

Now you can in catalog/view/theme/default/product/category.tpl use your code:

<?php if ($category_id == '1697') { ?>
       <a href="#"><img alt="Seagate Barracuda SSD's" class="img-responsive" src="image/catalog/Seagate-Barracuda-SSDs.jpg" /></a>
    <?php } ?>