php - OpenCart 在主页上显示类别图片?

标签 php image thumbnails opencart

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

我想要做的是在每个页面上显示来自商店类别页面的图像,因为我想将它实现到菜单中。你可以在这里明白我的意思:http://www.tomrawcliffe.com/portfolio/strings-r-us/

在我发现的 cetegory.tpl 文件中:

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

但我开始意识到这并不像将其复制并粘贴到 header.tpl 等中那么容易。

我该怎么办!?

最佳答案

好的,打开/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,你要适当的修改

关于php - OpenCart 在主页上显示类别图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8679580/

相关文章:

php - CodeIgniter 分页结果问题

php - 从数据库动态导航

java 用鼠标 move 图像

image - 地形图等高线提取

linkedin - 检索 Linkedin Video Post 的缩略图 (ugcPost API)

php - 来自 cronjobs 的 mySQL 锁定记录

php - 算出当月第四个星期六的日期

android - 如何在 android WebView 上显示全屏(centerCrop)图像?

python - 以编程方式为小视频生成缩略图 CAP

php - 使用 imagecopyresampled 裁剪图像的中心正方形