我想制作一个包含当前类别名称,描述和图像(拇指)的模块
代码只给出了应该是当前类别的主要类别。如何管理?我的模块中也有类别横幅。有没有办法从$ category ['description']
中得到它希望有人可以提供帮助。我试图从oter脚本中找到线索但是没有用。从category.tpl复制也没有做到这一点。
我在控制器/类别中有这个
<?php
class ControllerModuleLbMultiLevelCategory extends Controller {
public function index($setting) {
$this->load->language('module/lbmultilevelcategory');
$data['heading_title'] = $this->language->get('heading_title');
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
if (isset($parts[0])) {
$data['category_id'] = $parts[0];
} else {
$data['category_id'] = 0;
}
if (isset($parts[1])) {
$data['child_id'] = $parts[1];
} else {
$data['child_id'] = 0;
}
if (isset($parts[2])) {
$data['sisters_id'] = $parts[2];
} else {
$data['sisters_id'] = 0;
}
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
$total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id']));
$children_data = array();
$sister_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sister_data = array();
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if($sisters) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' =>$sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
} else {
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' =>'',
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
}
// image cat code
$this->load->model('tool/image');
$image = empty($category['image']) ? 'no_image.jpg' : $category['image'];
$thumb = $this->model_tool_image->resize($image, 50, 50);
$data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'],
'children' => $children_data,
'sister' => $sister_data,
'thumb' => $thumb,
'description' => $category['description'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/lbmultilevelcategory.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/module/lbmultilevelcategory.tpl', $data);
}else {
return $this->load->view('default/template/module/category.tpl', $data);
}
}
}
并将其用于查看tpl
<?php if ($categories) :
foreach ($categories as $category) {
if ($category['category_id'] == $category_id) {
if(isset($category)) {
?>
<h2> <?php
echo (html_entity_decode($category['name'], ENT_QUOTES, 'UTF-8')); ?> </h2>
<?php echo (html_entity_decode($category['description'], ENT_QUOTES, 'UTF-8')); ?>
<?php
}
}
} ?>
<?php endif; ?>