3

我需要在 Prestashop 主题的类别页面中列出同级类别。目前,它确实显示了子类别(如果有),但显示兄弟类别。

快速回答将不胜感激!谢谢。

4

2 回答 2

5

首先,我会在 /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();
    }
}

?>

我这是做到这一点的基本方法,我还没有测试它。您需要找到一种不在同级列表中列出当前类别的方法。

如果代码有效,您现在将在 category.tpl 中有一个名为 category_siblings 的数组,您现在需要例如复制 category.tpl 中输出子类别的代码并将子类别 arra 替换为 category_siblings 数组。

于 2012-07-02T18:01:00.577 回答
2

谢谢 - 效果很好!

您不必从数组中删除当前类别,只需将其标记为活动。您必须编辑 category.tpl 并在 foreach 子类别循环中插入:

<li {if $category->id == $subcategory.id_category}class="active"{/if}>

它非常棒的导航技巧!再感谢一次

于 2013-07-15T18:08:57.403 回答