2011-08-26 2 views
0

그래서 개념의 증거로 /[my-theme-name]/template/catalog/navigation/left.phtml에 다음 코드가 있습니다재귀 함수를 사용하여 젠토에서 카테고리의 중첩 된 목록을 인쇄

<?php 
$Mage_Catalog_Block_Navigation = new Mage_Catalog_Block_Navigation(); 
$categories = $Mage_Catalog_Block_Navigation->getStoreCategories(); 

function render_flat_nav($categories) { 
    $html = '<ul>'; 
    foreach($categories as $category) { 
     $html .= '<li><a href="' . $category->getCategoryUrl($cat) . '">' . 
        $category->getName() . "</a>\n"; 
     if($category->hasChildren()) { 
      $children = $category->getChildren(); 
      $html .= render_flat_nav($children); 
     } 
     $html .= '</li>'; 
    } 
    return $html . '</ul>'; 
} 
echo render_flat_nav($categories); ?> 

레벨 0 및 레벨 1 카테고리에 적합하지만 더 깊게 중첩 된 카테고리는 절대로 인쇄되지 않습니다.

그래서 $category->getChildren()은 내가 예상 한대로 되돌릴 수 없습니다. 거기에 내 재귀 함수와 함께 작동합니다 호출 할 수있는 방법이 있나요?

+0

'$ category-> getChildren()'이 반환하는 것은 무엇입니까? – xdazz

+0

클래스 모음을 반환하지만'getStoreCategories()'가 반환하는 콜렉션과 다른 점이 있다고 가정합니다. – Treffynnon

+0

범주의 하위 항목을 반환하지 않습니까? 나는 magento를 모른다, 문서를 확인하려고합니다. – xdazz

답변

1

나는이 문제에 대한 답을 발견하지만, 차선의 수 : 위의

<?php 
$Mage_Catalog_Block_Navigation = new Mage_Catalog_Block_Navigation(); 
$categories = $Mage_Catalog_Block_Navigation->getStoreCategories(); 

function render_flat_nav($categories) { 
    $html = '<ul>'; 
    foreach($categories as $category) { 
     $html .= '<li><a href="' . $category->getCategoryUrl($cat) . '">' . 
        $category->getName() . "</a>\n"; 
     if($category->hasChildren()) { 
      $children = Mage::getModel('catalog/category')->getCategories($category->entity_id); 
      $html .= render_flat_nav($children); 
      } 
     $html .= '</li>'; 
    } 
    return $html . '</ul>'; 
} 
echo render_flat_nav($categories); ?> 
0
$_category = Mage::getModel('catalog/category')->load(257);  
     $_categories = $_category 
        ->getCollection() 
        ->addAttributeToSelect(array('name', 'image', 'description')) 
        ->addIdFilter($_category->getChildren()); 

function render_flat_nav($categories) { 
    $html = '<ul>'; 
    foreach($categories as $category) { 
     $html .= '<li><a href="' . $category->getCategoryUrl($cat) . '">' . 
        $category->getName() . "</a>\n"; 
     if($category->hasChildren()) { 
      $children = Mage::getModel('catalog/category')->getCategories($category->entity_id); 
      $html .= render_flat_nav($children); 
      } 
     $html .= '</li>'; 
    } 
    return $html . '</ul>'; 
} 
echo render_flat_nav($_categories); 

덕분에 내가이 특정 범주의 ID와이 작품을 위해 작동하도록 관리 플랫 카테고리도 있습니다.

관련 문제