簡體   English   中英

opencart上的類別條件標簽

[英]Category Conditional tags on opencart

我正在使用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這是一張圖像,右側有說明

尚未測試,但這應該適合您。
$ 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
}

從事類似的工作。 希望它能對其他人有所幫助,請打破更多代碼:

目錄\\控制器\\產品

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM