title: Magento: display all level2 categories
body: <p>I have categories with 4 levels.<br>
  Example : <br>
  <code>level0category --&gt; level1category --&gt; level2category --&gt;lastlevel_level3cateogory</code><br>
  is it possible on lastlevel to display the categories that are in level2 and only? (on a block that i load a custom left.phtml)<br>
  I was thinking something with automatic category detection and not have to set cat_id=</p>
  
  <p>Edit: this is what i was looking for, after mix of code from different sources.</p>
  
  <pre><code>&lt;?php
      $currentCat = Mage::registry('current_category');
  
      if ( $currentCat-&gt;getParentId() == Mage::app()-&gt;getStore()-&gt;getRootCategoryId() )
      {
          // current category is a toplevel category
          $loadCategory = $currentCat;
      }
      else
      {
          // current category is a sub-(or subsub-, etc...)category of a toplevel category
          // load the parent category of the current category
          $loadCategory = Mage::getModel('catalog/category')-&gt;load($currentCat-&gt;getParentId());
          // @TODO enhance for more nested category levels to display sub-categories
      }    
      $subCategories = explode(',', $loadCategory-&gt;getChildren());
  
      foreach ( $subCategories as $subCategoryId )
      {
          $cat = Mage::getModel('catalog/category')-&gt;load($subCategoryId);
  
  
  if ($cat-&gt;getIsActive())
  {
      if ($currentCat-&gt;getEntityId() == $subCategoryId)
      {
          echo '&lt;li style="display:none;"&gt;'.$cat-&gt;getName().'&lt;/li&gt;';
      }
      else
      {
  
  
    echo '&lt;a href="'.$cat-&gt;getURL().'"&gt;'.$cat-&gt;getName().'&lt;/a&gt; &lt;br&gt;';    }
  }
  
      }
  ?&gt;
  </code></pre>