Opencart 在类别页面中获取 category_id [英] Opencart get category_id in category page
本文介绍了Opencart 在类别页面中获取 category_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图在类别页面中获取新"标签.例如,如果产品的类别为 219,则它会有贴纸.
Trying to get "new" sticker in category page. For example if product have category 219 it would have sticker.
我在控制器 category.php 中添加的内容
What I have added in controller category.php
$product_info = $this->model_catalog_product->getProduct($product_id);
$categories = $this->model_catalog_product->getCategories($product_info['$product_id']);
$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
$this->data['category_id'] = $categories_info['category_id'];
在 category.tpl 中
In category.tpl
<?php if($category_id=="219") { ?>
<img src="new.jpg">
<?php } ?>
但是什么都没有出现.
UPD:更改代码
$categories = $this->model_catalog_product->getCategories($result['product_id']);
$categories_info = $this->model_catalog_category->getCategory($categories[3]['category_id']);
$this->data['category_id'] = $categories_info['category_id'];
category.tpl
category.tpl
<?php if ($category_id=="219") { ?>
<?php } else { ?>
<?php } ?>
仅当我使用 $categories[3]['category_id'] 时才有效,但我无法使用 php 函数 in_array 搜索数组值.
It works only if i use $categories[3]['category_id'] but I can't search value it array with php function in_array.
推荐答案
如果你想为模板发送一些数据,你必须使用 $data 数组.
If you want send some data for template you have to use $data array.
例如:
$data['category_id'] = $categories_info['category_id'];
然后使用 $category_id
这篇关于Opencart 在类别页面中获取 category_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文