将图像添加到子类别而不是文本 link PHP-OPENCART

Add image to sub-category instead of text link PHP-OPENCART

我是php的新手,与opencart一样。我想添加带有 link 的图像,而不是传统的 links.

列表

http://www.metroingeni.ro/aparatura/cantare-si-sisteme-de-cantarire

我要实施的示例。

好的,我想我明白你想要什么了。

首先你需要找到一个负责类别视图的控制器,你可以在catalog/controller/product/category.php文件中找到它(我假设它是OC2)。在第 160 行附近的某处,您会看到:

$data['categories'][] = array(
    'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
    'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
);

替换为

$data['categories'][] = array(
    'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
    'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
    'image'=> $result['image']
);

然后在您的类别视图中,位于第 35 和 45 行附近的 catalog/view/theme/default/template/product/category.tpl 处,您可以将我们之前从控制器获得的类别图像以 <?php echo $category['image']; ?>.[= 的形式放置17=]


<?php echo $category['image']; ?> 在您看来 category.tpl 是图像的相对 URL。把它放在你的图像源属性中。必须在类别的 foreach 循环内。

希望这对您有所帮助,我还没有测试过这段代码,但它应该可以工作。

此处假设默认安装了 opencart 2,但该概念应适用于任何或大多数主题或扩展。