2013-04-11 142 views
2

我試圖顯示所有子類別內prestashop類別的子類別菜單。默認情況下,您只能看到類別內的子類別菜單,但不能看到子類別的「兄弟」子類別。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} 

任何想法?

非常感謝

+0

你需要更具體些。你有什麼嘗試?什麼不起作用? – 2013-04-11 01:41:27

+0

我試圖在子類別頁面中添加此代碼:{$subcategory.name|escape:'htmlall':'UTF-8'}並沒有工作,我想我需要編輯$給其他人在子類別頁面內工作。 – user2268430 2013-04-14 02:10:47

回答

0

一如既往我不給你一個完整的代碼,但我告訴你該怎麼做。 在smarty中,您需要創建一個函數,該函數需要父類別的參數數量爲 ,並且在此函數中您需要使用Category :: getChildren($ id_category);然後在smarty中,只需要通過smarty函數循環。

關於

對不起我的英文。

0

對於開始我就已經創造了/重寫一個覆蓋文件/控制器/,命名爲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(); 
    } 
} 

?> 

而且在產品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