简体   繁体   中英

Category Conditional tags on opencart

I'm using opencart v.1.5.1 and on the /catalog/view/theme/default/template/product/category.tpl

how do I write a condition like this:

If main current display is of a parent category:
show this image

else (if it's a subcategory display ):
show different image

because this is what i want to achieve:

on this site (parent category): http://www.guitarplayback.com/Jam-Tracks it's a banner image

on the subcategory : http://www.guitarplayback.com/Jam-Tracks/Ballad-Jam-Tracks it's an image with description on the right side

Not test this yet but this should work for you.
Try this on controller/product/category.php before $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';
  }
}

On category.tpl

if (isset($topCatImage)) {
   show this image
} else {
   show other image
}

working on something similar. Hope it helps others, Got break some more code:

catalog\\controller\\product

$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'];
} 

catalog\\model\\catalog

 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;

}

catalog\\view\\theme\\default\\template\\product

 <?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 } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM