【问题标题】:Get sibling categories in category.tpl for the current category in prestashop在 category.tpl 中获取 prestashop 中当前类别的同级类别
【发布时间】:2012-06-27 17:52:06
【问题描述】:

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

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

【问题讨论】:

    标签: categories prestashop


    【解决方案1】:

    首先我会在 /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 数组。

    【讨论】:

    • 非常感谢 Niclas,我会尽力让你知道,我已经祈祷了!只是一件事,在哪里可以得到 Prestashop 的功能列表,就像 Wordpress 的 codex 一样?
    • 还没有看到 Prestashop 的法典。但是您可能可以使用文档生成器构建一个:en.wikipedia.org/wiki/Comparison_of_documentation_generators
    【解决方案2】:

    谢谢 - 效果很好!

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      • 2016-04-25
      相关资源
      最近更新 更多