2012-05-08 41 views
0

只是給你一個想法。我有3個級別的類別。
頂級>次級類別>子類別兒童Magento正確顯示主要和一個子類別的方法

我不想展示的是子類別的子類。

下面的代碼顯示了每個類別。 (對不起,貼的格式不是很好。)

<?php 
// ---- PRODUCT NAVIGATION ---- \\ 
$nav_obj = new Mage_Catalog_Block_Navigation(); 
$store_cats = $nav_obj->getStoreCategories(); 
$current_cat = $nav_obj->getCurrentCategory(); 
?> 

<ul> 

<?php foreach ($store_cats as $cat):?> 
<?php 
$ids = strtolower(str_replace(" ", "_", $cat->getName())); 
$ids = str_replace("&", "", $ids); 
?> 


<li class="parent" id="<?php echo $ids; ?>"><?php echo $cat->getName()?> 

<ul> 
<?php foreach (Mage::getModel('catalog/category')->load($cat->getId())->getChildrenCategories() as $childCategory): ?> 
<li><a href="<?php echo $childCategory->getUrl(); ?>"> 
<?php echo $childCategory->getName()?></a></li> 
<?php endforeach; ?> 
</ul> 
</li> 

<?php endforeach; ?> 

回答

0

我有一個類似的事情,我正在努力。我基本上將每個類別傳遞並呈現我想呈現的內容:

<?php # get category list ?> 
<?php $_helper = Mage::helper('catalog/category') ?> 
<?php $_categories = $_helper->getStoreCategories() ?> 

<?php foreach($_categories as $_category) : ?> 
    <?php # turn it into the proper model object ?> 
    <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?> 
    <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>   
    <?php foreach($_category->getChildrenCategories() as $_subCategory) : ?> 
     <a href="<?php echo $_subCategory->getUrl() ?>"><?php echo $_subCategory->getName() ?></a> 
    <?php endforeach ?> 
<?php endforeach ?> 
相關問題