我一直在尝试实现在侧边栏类别模块中显示类别的第二个子项,如下所示
例如:Toys > boys > RC cars
目前有这个
<ul>
<?php foreach ($categories as $category) { ?>
<?php if ($category['category_id'] == $category_id) { ?>
<li class="cat-active">
<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
<?php } else { ?>
<li>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<b class="cc"></b>
<ul class="col-subcat">
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
只显示
男孩>玩具
我不确定如何显示第二个孩子(">男孩>遥控车的玩具")泰建议
您必须自定义 2 个文件。
- 目录/控制器/模块/类别.php - 39 行
找到"foreach ($children as $child) {",并在它下面放置以下代码。
$children_data_2 = array();
$children_2 = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($children_2 as $child_2) {
$filter_data = array(
'filter_category_id' => $child_2['category_id'],
'filter_sub_category' => true
);
$children_data_2[] = array(
'category_id' => $child_2['category_id'],
'name' => $child_2['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $child_2['category_id'])
);
}
改变
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
自
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
'children' => $children_data_2 // insert this line
);
- 目录/视图/主题/
- [您的主题目录]/模板/模块/类别.tpl
<ul>
<?php foreach ($categories as $category) { ?>
<?php if ($category['category_id'] == $category_id) { ?>
<li class="cat-active">
<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
<?php } else { ?>
<li>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<b class="cc"></b>
<ul class="col-subcat">
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
<?php } ?>
<?php if ($child['children']) { ?>
<b class="cc"></b>
<ul class="col-subcat">
<?php foreach ($child['children'] as $child_2) { ?>
<li>
<?php if ($child_2['category_id'] == $child_id) { ?>
<a href="<?php echo $child_2['href']; ?>" class="active"><?php echo $child_2['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child_2['href']; ?>"><?php echo $child_2['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>