如何在magento中显示除默认类别之外的新根类别

时间:2014-01-03 06:07:59

标签: php magento

在我的网站上,我有一个默认菜单,总是显示在标题部分。现在我想添加另一个根类别,它将显示在特定页面(不是所有页面)中。我已经从magento admin创建了一个新的根类别,但不知道如何在前端只显示这个类别。指出我的新类别ID是'12'我试过

 <?php
      $category = Mage::getModel('catalog/category'); 
      $tree=$category->getTreeModel(); 
      $tree->load();
      $ids = $tree->getCollection()->getAllIds(); 
      $arr = array();
      if ($ids){ 
    foreach ($ids as $id){ 
     $cat = Mage::getModel('catalog/category'); 
     $cat->load($id);
    $arr[$id]=$cat->getName();
     } 
    }
 ?>
  <?php 
  $cat_id = Mage::app()->getStore()->getRootCategoryId(); 
$collection = Mage::getModel('catalog/category')->getCategories($cat_id,12, true, true);
$position=array();
$index=array();
foreach($collection as $key=>$cat) {
    array_push($index,$cat->getPosition());
}
asort($index);
echo '<ul class="jetmenu blue">';
$c=0;
foreach($index as $index_new){
foreach($collection as $cat){
    if( $index_new==$cat->getPosition())
    {
    echo '<li><a href="'.$cat->getURL().'" />'.$cat->getName().'</a>';
    $cat_id=$cat->getId();
    $subcategory_html=GetSubcategory($cat_id);
    echo $subcategory_html;
    echo '</li>'; 
    }
}
}
 ?> 
    </ul>

但这只显示默认类别,而不是其他类别。请帮助。

enter image description here

1 个答案:

答案 0 :(得分:0)

显示包含所有类别的根类别。

<?php

  $root_category = Mage::getModel('catalog/category')->load(12); // Put your root category ID here.
  $subcategories = $root_category->getChildren();
  foreach(explode(',',$subcategories) as $subcategory) {
        $category = Mage::getModel('catalog/category')->load($subcategory);
        echo '<a href="'.$category->getURL() .'" />'.$category->getName().'</a><br/>';
  }

  ?>