gpt4 book ai didi

php - 有什么方法可以在站点地图页面上显示 3 个以上的类别? (打开购物车 3)

转载 作者:可可西里 更新时间:2023-10-31 23:36:24 25 4
gpt4 key购买 nike

我正在寻找一种在站点地图页面上显示更多类别的方法(默认情况下为 3)。

我尝试用以下代码修改模板的sitemap.twig:

<li><a href="{{ category_3.href }}">{{ category_3.name }}</a>
{% if category_3.children %}
<ul>
{% for category_4 in category_3.children %}
<li><a href="{{ category_4.href }}">{{ category_4.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
</li>

但是没有用。

然后我还尝试用一个 foreach 循环更改 /catalog/controller/information/sitemap.php:

foreach ($categories_3 as $category_3) {
$level_4_data = array();

$categories_4 = $this->model_catalog_category->getCategories($category_3['category_id']);

foreach ($categories_4 as $category_4) {
$level_4_data[] = array(
'name' => $category_4['name'],
'href' => $this->url->link('product/category', 'path=' . $category_1['category_id'] . '_' . $category_2['category_id'] . '_' . $category_3['category_id'] . '_' . $category_4['category_id'])
);
}

$level_3_data[] = array(
'name' => $category_3['name'],
'children' => $level_4_data,
'href' => $this->url->link('product/category', 'path=' . $category_1['category_id'] . '_' . $category_2['category_id'] . '_' . $category_3['category_id'])
);
}

然后什么也没发生。所以我想问一下有什么办法可以解决我的问题吗?

最佳答案

您可以这样显示所有类别及其子类别(类别树):

Controller 文件:

catalog\controller\information\sitemap.php

在关闭之前,在此文件的末尾添加这两个函数

protected $categoryTree = '';
protected function buildCategoryTree($parent_id = 0, $categories = null, $path = ''){
$categories = $this->model_catalog_category->getCategories($parent_id);
if($categories){
$this->categoryTree .= '<ul>';
foreach ($categories as $category) {
$path = $path ? $path . $category['category_id'] : $category['category_id'];
$href = $this->url->link('product/category', 'path=' . $path);
$categories = $this->model_catalog_category->getCategories($category['category_id']);
$this->categoryTree .= '<li><a href="' . $href . '">' . $category['name'] . '</a>';
$this->buildCategoryTree($category['category_id'], $categories, $path . '_');
$this->categoryTree .= '</li>';
}
$this->categoryTree .= '</ul>';
}
}

查找:

$this->response->setOutput($this->load->view('information/sitemap', $data));

在它之前添加:

$this->buildCategoryTree();
$data['categories'] = $this->categoryTree;

查看文件:

catalog\view\theme\*\template\information\sitemap.twig

查找:

<ul>
{% for category_1 in categories %}
<li><a href="{{ category_1.href }}">{{ category_1.name }}</a>
{% if category_1.children %}
<ul>
{% for category_2 in category_1.children %}
<li><a href="{{ category_2.href }}">{{ category_2.name }}</a>
{% if category_2.children %}
<ul>
{% for category_3 in category_2.children %}
<li><a href="{{ category_3.href }}">{{ category_3.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>

将其替换为:

{{ categories }}

您可以删除 Controller 文件中的主要类别 foreach 循环。

关于php - 有什么方法可以在站点地图页面上显示 3 个以上的类别? (打开购物车 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48672675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com