首先,我会在 /override/controllers/ 中创建一个覆盖文件,名为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();
}
}
?>
在product-list.tpl文件中:
<ul>
{foreach from=$category_siblings item=elemento}
<a href="{$link->getCategoryLink($elemento.id_category, $elemento.link_rewrite)|escape:'htmlall':'UTF-8'}" class="cat_name"> <li {if $category->id == $elemento.id_category}class="active"{/if}> {$elemento.name} </li> </a>
{/foreach}
</ul>
通过在 category.tpl 中为 prestashop 中的当前类别获取同级类别