OpenCart在主页上显示分类图片?

问题描述 投票:7回答:1

我使用的是最新版本的open cart。

我想做的是在每个页面上显示商店分类页的图片,因为我想把它实现在菜单上。你可以在这里看到我的意思。http:/www.tomrawcliffe.comportfoliostrings-r-us

在cetegory.tpl文件中我发现。

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

但我意识到这不是简单的复制和粘贴到header. tpl等文件中就能实现的

我该怎么做!?

php image thumbnails opencart
1个回答
12
投票

好的,打开 /catalog/controller/common/header.php

找到这个代码

            // 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'])
            );

改为

            // 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'])
            );

然后在 /catalog/view/theme/[your-theme-name]/template/common/header.tpl 只需用 $category['thumb'] 随处可见

请注意,在上面的代码中,我已经将宽度和高度设置为100px,你应该根据实际情况进行修改。

© www.soinside.com 2019 - 2024. All rights reserved.