【问题标题】:Prestashop subcategories menu inside a subcategoryPrestashop 子类别中的子类别菜单
【发布时间】:2013-04-03 02:03:54
【问题描述】:

我正在尝试在所有子类别中显示 prestashop 类别的子类别菜单。默认情况下,您只能看到类别中的子类别菜单,但看不到子类别的“兄弟”子类别。

我想我只需要让这段代码在一个子类别中工作,因为这段代码在一个类别中运行良好:

{foreach from=$subcategories item=subcategory}
<li >    <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}"
class="cat_name">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
</li>    {/foreach}

有什么想法吗?

非常感谢

【问题讨论】:

  • 您需要更具体一点。你试过什么?什么没用?
  • 我已尝试添加此代码:{$subcategory.name|escape:'htmlall':'UTF-8'} 在子类别页面中并且没有工作,我想我需要将 $ 编辑给其他人才能工作在子类别页面内。

标签: prestashop


【解决方案1】:

一如既往,我不会给你一个完整的代码,但我会告诉你怎么做。 在 smarty 中,您需要创建一个函数,该函数将父类别的参数号作为参数, 在这个函数中你需要使用 Category::getChildren( $id_category );然后在 smarty 中你只需要通过 smarty 函数循环。

问候

对不起我的英语。

【讨论】:

    【解决方案2】:

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

    通过Get sibling categories in category.tpl for the current category in prestashop

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-23
      • 2018-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      相关资源
      最近更新 更多