1

In my website I have a default menu which always shows in the header part. Now I want to add another root category which will show up in a specific page(not all pages). I already created a new root category from magento admin but don't know how to show only this category in frontend. point that my new category id is '12' I tried

<?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>

but this only shows the default category, not the other category.

2 Answers 2

1

You can pass your category id in and based on that you got all category details. if you want to get sub category then same process but you have to pass $cat->getId() which we will get from the for loop.

$category = Mage::getModel('catalog/category')->load($categoryId);
$coll = $category->getResourceCollection();
$coll->addAttributeToSelect(*);
$result = '';
foreach ($coll as $cat) {
  echo $cat->getName().'/'. $cat->getId();
}

hope you got the solutions.

0

To display the root category with all categories underneath it.

<?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/>';
  }

  ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.