【问题标题】:Prestashop - how to write parent category on breadcrumbsPrestashop - 如何在面包屑上写父类别
【发布时间】:2016-11-24 16:02:57
【问题描述】:

我正在 category.tpl 中的 prestashop 上制作自己的面包屑。我有 2 个深度菜单。在子类别页面中,我想在我的面包屑中添加上层类别名称并链接到它。

例如我有菜单 -水果 - -苹果 - -香蕉 -蔬菜 -面包 - -卷 ---面包

当我在苹果页面上时,我想要这样的面包屑:“home

对不起我的英语。希望得到您的回答。

【问题讨论】:

    标签: smarty prestashop breadcrumbs


    【解决方案1】:

    您可以使用 id_parent 属性获取父类别:

    $category->id_parent
    

    您还可以查看当前类别的层级深度以了解何时显示父类别:

    {if $category->level_depth > some_int_value}
        {* display parent breadcrumb *}
    {/if}
    

    祝你好运。

    【讨论】:

    • 我知道我可以得到父类别的ID,但我想有父类别的链接和名称。
    • 最简单的方法是在CategoryController前面设置parent_category作为smarty的参数。然后,您可以像普通类别一样在 TPL 中访问类别名称和链接。对于链接,您必须在 category.tpl 中使用 $link->getCategoryLink(...)
    • 请帮我在 Controller 中设置它并在 category.tpl 中使用它。我不知道该怎么做。
    • 我建议您为此聘请一些开发人员。如果您不知道如何执行此操作,即使有详细的教程,您也可能会导致您的商店崩溃。祝你好运。
    • 我非常想要这个详细的教程,如果没有问题,请。我正在制作副本,所以这对我的商店没有危险。
    【解决方案2】:

    这并不完全是原始问题的答案,但它可以帮助想要对类别面包屑进行一些更改的人

    presta 1.7 - 如果您想将 根类别 添加到面包屑

    原路径:首页 > 分类 > 子分类1 > ...

    主页 > 根类别 > 类别 > 子类别 1 > ...

    controllers/front/listingCategoryController.php

    public function getBreadcrumbLinks()
    {
        $breadcrumb = parent::getBreadcrumbLinks();
        // adding root category to breadcrumbs
        $rootCategory = Category::getRootCategory();
        $breadcrumb['links'][] = array(
            'title' => $rootCategory->name,
            'url'   => $this->context->link->getCategoryLink($rootCategory->id, $rootCategory->link_rewrite),
        );
        //
    
        foreach ($this->category->getAllParents() as $category) {
            if ($category->id_parent != 0 && ! $category->is_root_category) {
                $breadcrumb['links'][] = $this->getCategoryPath($category);
            }
        }
    
        $breadcrumb['links'][] = $this->getCategoryPath($this->category);
    
        return $breadcrumb;
    }
    

    【讨论】:

    • 解释一下如何?应使用代码工具突出显示代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    相关资源
    最近更新 更多