我想要foreachOpenCart类别模块的第三级,这里是只生成2级别类别的代码,请帮助和修改,以便它将创建第三级:
<ul id="menu">
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
</li>
<?php } ?>
</ul>
Run Code Online (Sandbox Code Playgroud)
小智 7
首先,您需要编辑标题控制器:
转到目录 - > controller-> common-> header.php
编辑创建$ categories变量的部分.通过以下脚本更新:
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sec_children_data = array();
$sec_children = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($sec_children as $sec_child) {
$sec_children_data[] = array(
'name' => $sec_child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $child['category_id'] . '_' . $sec_child['category_id'])
);
}
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']), 'children' => $sec_children_data
);
}
// Level 1
$this->data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
Run Code Online (Sandbox Code Playgroud)
然后更新视图文件以显示第三级类别.
| 归档时间: |
|
| 查看次数: |
9953 次 |
| 最近记录: |