OpenCart show category images on homepage?

前端 未结 1 2093
北海茫月
北海茫月 2021-02-15 23:09

I\'m using the most up to date version of open cart.

What I\'m wanting to do is show the image from the store category page on every page page, as I\'m wanting to imple

相关标签:
1条回答
  • 2021-02-15 23:51

    OK, open up /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 simply use $category['thumb'] wherever you need it

    note that I've set the width and height to 100px in the above code, and you should change it as appropriate

    0 讨论(0)
提交回复
热议问题