如何创建单独的模板以在Opencart 2中输出类别?

时间:2016-11-18 09:50:43

标签: php content-management-system opencart

OpenCart 2上的商店中有几类商品,需要相互结构和设计。如何实施?通过创建控制器和模板输出访问选项,但不起作用...

2 个答案:

答案 0 :(得分:0)

在Opencart 2中,class与您正在查看的网页相关body,例如,如果您属于某个类别,class <body class="product-category-20"> 应为:

body.product-category-20 {
  background-color: red;
}

你可以像这样使用它:

body.product-category-21 {
  background-color: green;
}

另一个类别;

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]

要为每个类别指定不同的模块,您可以添加新布局,然后在编辑或创建新类别时从设计选项卡中选择此布局。

答案 1 :(得分:0)

解决。 有人可以派上用场。

在文件 \ catalog \ controller \ product \ category.php

替换代码:

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/product/category.tpl', $data));
        }

对此:

$template = 'category.tpl';
        if ($category_id == 72) { $template = 'category-72.tpl'; }

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/'.$template)) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/'.$template, $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/product/'.$template, $data));
        }

而不是72把你的类别ID。

在此创建模板我们的类别:

<强> \目录\视图\主题\ NAME_THEME \模板\产品\类别-72.tpl

然后转到管理员 - &gt; 模块 - &gt; 修改器并更新缓存。完成。