title: How To Get Sub Categories in Magento ?`
body: <p>I am playing with magento's home page where I have created a tab Which Shows all the categories including Root, categories, and Sub Categories (In One Tab). Now I want to Show Only Main Categories( Whose Parent Is Root) in main Tab And under Each Category I want to List Their respective Sub Categories. I wrote The following Code to achieve a part of this,</p>
  
  <p>MODEL CLASS </p>
  
  <pre><code>public function getsubCategory($parent)
  {
  
      $subcategoryCollection = Mage::getModel('catalog/category')
      -&gt;getCollection()
      -&gt;addAttributeToFilter('parent_id', $parent);
         return $subcategoryCollection;
  </code></pre>
  
  <p>BLOCK CLASS</p>
  
  <pre><code>protected function b4Html_subcategory($parent)
  {
      $catModel = Mage::getModel('Pragtech_Sweet/category');
      $mysubCategory = $catModel-&gt;getsubCategory($parent);
      $this-&gt;mysubCategory = $myCategory; 
      return $mysubCategory;
  }
  </code></pre>
  
  <p>TEMPLATE FILE</p>
  
  <pre><code>$obj = new Pragtech_Sweet_Block_Category();
  $collection = $obj-&gt;b4Html();
  foreach ($collection as $category)
      {
      $name = $category-&gt;getName();
      $parent = $category-&gt;getParent_id();
  
      foreach ($obj-&gt;b4Html_subcategory($parent) as $subcategory)
      {   
         $subname = $subcategory-&gt;getName();
         //Here Will Go Ther Code For Sub Categories
  
      }
  </code></pre>
  
  <p>but it doesn't work.. I am unable to understand where I am doing wrong... Can anyone help me out </p>