将图像添加到子类别中,而不是文本链接


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

我是php的新手,与openart相同。我想添加图像w/link而不是传统的链接列表。

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

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


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

希望这有帮助,我没有测试这段代码,但它应该工作。

这里假设openart 2的默认安装,但这个概念应该适用于任何或大多数主题或扩展。