Reputation: 87
i want create a categories grid image only on homepage of my opencart 2.x ecommerce , i have found various guide online but in every case require to customize the default categories.php then impinging on all pages, example i followed this guide How to display Category images in OpenCart
in categories.php
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'],
'image' => $category['image'],
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
in categories.tpl
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><img src="<?php echo $category['image']; ?>" alt="<?php echo $category['name']; ?>"></a></li>
<?php } ?>
so how i can do it for only homepage ?
Upvotes: 1
Views: 1355
Reputation: 1136
I would highly recommend you leverage OpenCart's extension/module system so that you don't have to actually modify the default Controller file but in terms of the way you express that you would like it to be done you must take what you've done to the $data
array in the categories.php
controller file and simply do the same in the common/home.php
controller file.
After the data required is accessible by the template I would recommend you install the HTML Content extension via the Admin Panel and then simply add your template code to a layout module that way you can easily disable/enable it at will without the need to edit code.
Once you have created the code necessary in an HTML Content module add it to your default Home Page layout.
Upvotes: 0