opencart href链接取决于category_id

时间:2017-03-21 12:22:42

标签: if-statement opencart

是Opencart中的新手我需要一个if then语句,它将加载不同的.tpl分页,取决于category_id。

我尝试过但显示错误

  

解析错误:第28行的D:\ xampp \ htdocs \ ramesh \ lmw \ catalog \ controller \ product \ sub_category.php中的语法错误,意外'if'(T_IF),期待')'

这是我的代码

sub_category.php

foreach ($category_info as $result) {
            $data['categories'][] = array(
                'name' => $result['name'],
                'parent_id' => $result['parent_id'],
                'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
                'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
                #'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
                #'href' => $this->url->link('product/sub_category')
                if($result['category_id'] == 24)
                {
                'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
                }
                else
                {
                    'href' => $this->url->link('product/filter', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
                }
            );
        }

2 个答案:

答案 0 :(得分:1)

试试这个,

foreach ($category_info as $result) {
        $data['categories'][] = array(
            'name' => $result['name'],
            'parent_id' => $result['parent_id'],
            'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
            'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
            #'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
            #'href' => $this->url->link('product/sub_category')
            if($result['category_id'] == 24)
            {
            'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
            }
            else
            {
                'href' => $this->url->link('product/filter', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
            };
        );
    }

看起来你错过了一个&#34 ;;"在if语句之后。你也应该使用/ * not"#"

注释掉

答案 1 :(得分:0)

    foreach ($category_info as $result) {
 if($result['category_id']==24)
 {
    $link1 = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
 }
else
{
    $link1 = $this->url->link($_SERVER["REQUEST_URI"]);
}
$data['categories'][] = array(
    'name' => $result['name'],
    'parent_id' => $result['parent_id'],
    'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
    'href' => $this->url->link('product/sub_category')
    'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])*/
    'href' => $link1
);