如何在Opencart 2.3.0.2中为某个类别的产品设置样式

时间:2017-03-28 11:43:45

标签: php css opencart opencart2.x opencart2.3

我想在opencart 2.3.0.2中为特定类别的产品添加独特风格。

2 个答案:

答案 0 :(得分:0)

在Opencart 2.x中,body针对每个不同的网页都有不同的类,例如类似的类别:<body class="product-category-59"> 对于另一个类别:<body class="product-category-70">

您可以将这些类用于您的样式,例如:

.product-category-59 a {
    color: red;
}
.product-category-70 a {
    color: green;
}

答案 1 :(得分:0)

如果您想更改特定类别的样式,包括HTML,那么首先

开放

catalog/controller/extension/module/category.php

在文件末尾你会找到一行:

return $this->load->view('extension/module/category', $data);

您可以在此处为特定类别ID添加if else条件,例如:

if ($data['category_id'] == 25){
            return $this->load->view('extension/module/categorycustom', $data);
} else {
            return $this->load->view('extension/module/category', $data);
}

在以下位置添加新文件:

目录/视图/主题/默认/模板/扩展/模块/ categorycustom.tpl

并从

复制内容
catalog/view/theme/default/template/extension/module/category.tpl

这将更改左侧过滤器数据的内容。

如果您想更改右侧的主要内容,请打开:

catalog/controller/product/category.php

查找377左右的行

$this->response->setOutput($this->load->view('product/category', $data));

在此处添加if else条件以更改页面的主要内容。像:

if ($category_info['category_id'] == 28){
        $this->response->setOutput($this->load->view('product/categorynew', $data));
} else {
        $this->response->setOutput($this->load->view('product/category', $data));
}

现在添加新文件:

catalog/view/theme/default/template/product/categorynew.tpl

复制内容:

catalog/view/theme/default/template/product/category.tpl

这样您就可以完全更改特定类别页面的布局。