OpenCart show category images on the main page?

I use the latest version of the open cart.

What I want to do is show the image from the store category page on each page of the page, since I want to implement it in the menu. You can see what I mean here: http://www.tomrawcliffe.com/portfolio/strings-r-us/

In the cetegory.tpl file, I found:

<?php if ($thumb) { ?> <div class="image"><img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ? >" /></div> <?php } ?> 

But I realized that it is not as simple as copying and pasting it into header.tpl, etc.

What should I do??

+6
source share
1 answer

OK, open /catalog/controller/common/header.php

Find this code

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

change it to

  // Level 1 $this->load->model('tool/image'); $image = empty($category['image']) ? 'no_image.jpg' : $category['image']; $thumb = $this->model_tool_image->resize($image, 100, 100); $this->data['categories'][] = array( 'name' => $category['name'], 'children' => $children_data, 'column' => $category['column'] ? $category['column'] : 1, 'thumb' => $thumb, 'href' => $this->url->link('product/category', 'path=' . $category['category_id']) ); 

Then in /catalog/view/theme/[your-theme-name]/template/common/header.tpl just use $category['thumb'] where you need it

Notice that I set the width and height to 100px in the above code, and you should change it accordingly

+11
source

Source: https://habr.com/ru/post/904746/


All Articles