0

我正在使用 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 这是一张图片,右侧有描述

4

2 回答 2

3

尚未对此进行测试,但这应该对您有用。在$this->data['products'] = array();之前
在 controller/product/category.php 上试试这个

$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
}
于 2011-09-19T04:06:59.443 回答
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 } ?>
于 2012-12-23T19:13:28.163 回答