在category.tpl中获取prestashop中当前类别的同级类别 [英] Get sibling categories in category.tpl for the current category in prestashop
问题描述
我需要在Prestashop主题的类别页面中列出兄弟类别。目前,它确实显示子类别,但不是同级类别。
I need to list sibling categories in the category page in a Prestashop theme. Currently it does show the sub-categories if any but not the sibling categories.
一个快速答案确实不胜感激!谢谢。
A quick answer would really be appreciated! Thanks.
推荐答案
首先,我会在/ override / controllers /中创建一个覆盖文件,名为CategoryController.php
For to start i would have created a override file in /override/controllers/, named CategoryController.php
并添加以下内容:
<?php
class CategoryController extends CategoryControllerCore
{
public function displayContent()
{
// Get the global smarty object.
global $smarty;
// Get current category's parent.
$parent_category = new Category($this->category->id_parent, self::$cookie->id_lang);
// Get parent category's subcategories (which is current category's siblings, including it self).
$category_siblings = $parent_category->getSubCategories((int)self::$cookie->id_lang)
/* Assign your siblings array to smarty. */
$smarty->assign(
array(
"category_siblings" => $category_siblings
)
);
/* This we run the normal displayContent, but pass the siblings array to
category.tpl */
parent::displayContent();
}
}
?>
我这是基本的操作方式,我还没有测试过。您需要找到一种不在同级列表中列出当前类别的方法。
I this the basic way to do it, i have not tested it get. You need to find a way to not list current category in the list of siblings.
如果代码有效,您现在将在category.tpl中有一个名为category_siblings的数组,您现在需要例如复制输出子类别的category.tpl中的代码,并用category_siblings数组替换子类别arra。
If the code works you will now have an array in category.tpl named category_siblings, you now need to for example copy the code in category.tpl that outputs the subcategories and replace the subcategories arra with the category_siblings array.
这篇关于在category.tpl中获取prestashop中当前类别的同级类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!