我正在使用opencart v.1.5.1 /catalog/view/theme/default/template/product/category.tpl
我该怎么写这样的条件:
If main current display is of a parent category:
show this image
else (if it's a subcategory display ):
show different image
因为这是我想要实现的目标:
此网站上的(父类别):http://www.guitarplayback.com/Jam-Tracks 这是一个横幅图像
子类别上的:http://www.guitarplayback.com/Jam-Tracks/Ballad-Jam-Tracks 这是右侧描述的图像
答案 0 :(得分:3)
尚未对此进行测试,但这对您有用 在控制器/产品/ category.php 之前尝试此操作 $ this-> data ['products'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['category_id'] == $category_id && $category['top']) {
$this->data['topCatImage'] = '1';
}
}
在category.tpl
上if (isset($topCatImage)) {
show this image
} else {
show other image
}
答案 1 :(得分:0)
从事类似工作。希望它能帮助别人,打破一些代码:
<强>目录\控制器\产品强>
$cat_array = explode ("_", $path);
$top_cat_id = $cat_array[0];
$cat_Image = $this->model_catalog_category->getCatImage($top_cat_id);
if ($cat_Image) {
//show this image
$this->data['image'] = $cat_Image['image'];
}
<强>目录\模型\目录强>
public function getCatImage($category_id) {
$query = $this->db->query("SELECT image FROM " . DB_PREFIX .
"category AS cat LEFT JOIN category AS cats ON cats.parent_id = cat.category_id WHERE cat.parent_id =0 AND cat.category_id = '" . (int)$category_id . "'");
return $query->row;
}
<强>目录\视图\主题\默认\模板\产品强>
<?php if ($image) { ?>
<div class="image"><img src="<?php echo $image; ?>" alt="<?php echo $heading_title; ?>" /></div>
<?php } else { ?>
<div class="image"><img src="<?php echo $OTHERimage; ?>" alt="<?php echo $heading_title; ?>" /></div>
<?php } ?>