我是Opencart中的新手,我需要一条If then语句,该语句将加载不同的分页.tpl
取决于category_id。
我试过了,但显示错误,例如
解析错误:语法错误,意外的"if"(T_IF(,期望在第 28 行的 D:\xampp\htdocs\ramesh\lmw\catalog\controller\product\sub_category.php 中出现"(">
这是我的代码
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'])
}
);
}
试试这个,
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'])
};
);
}
看起来您在 if 语句后错过了一个";"。此外,您应该使用/* 而不是"#"注释掉
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
);