OpenCart show category images on homepage? [closed]

徘徊边缘 提交于 2019-12-21 05:09:20

问题


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 implement it into 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've come to realise that it's not as easy as copy and pasting this into the header.tpl etc.

What do I do!?


回答1:


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



来源:https://stackoverflow.com/questions/8679580/opencart-show-category-images-on-homepage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!