【问题标题】:OpenCart show category images on homepage?OpenCart 在主页上显示类别图像?
【发布时间】:2012-01-30 13:31:06
【问题描述】:

我正在使用最新版本的开放式购物车。

我想要做的是在每个页面页面上显示来自商店类别页面的图像,因为我想将它实现到菜单中。你可以在这里看到我的意思: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 等那样简单。

我该怎么办!?

【问题讨论】:

    标签: php image thumbnails opencart


    【解决方案1】:

    好的,打开/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,您应该根据需要进行更改

    【讨论】:

    • 我试图解释我最好的,但没有完全明白。我想要的是在菜单中显示的类别图像以及类别名称。而且我只想要父类别图像,而不是子类别。这样更好吗?
    • 看看上面的,应该能满足你的需要
    • 你绝对的传奇!谢谢。
    • 没问题。请使用投票旁边的勾号标记答案:)
    • 非常感谢你,我为 Opencart 3.x 编辑了它并使用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 2015-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多