display current parent category and their subcategory with jquery show hide option in magento

<?php foreach ($children as $category): ?>
  <?php if($category->getIsActive()): ?>
      <?php $cate =Mage::getSingleton('catalog/category')->getUrl($category).'id/'.$category->getId(); ?>
 
   <?php
           $class = '';
        if (Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId() == $category->getId())
        {
            $class = ' class="active"';
        }
        else{
           
            $class= ' class="inactive"';
        }
       
       
       
        if ($category->hasChildren()) {
    $subCategories = $category->getChildren();
        echo '<li'.$class.'><a href="'.$cate.'">'.$category->getName().'</a><ul id="show">';
        //$category = Mage::registry('current_category');


foreach($subCategories as $sub) {
     $catese =Mage::getSingleton('catalog/category')->getUrl($sub).'id/'.$sub->getId();
   
      $class1 = '';
        if (Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId() == $sub->getId())
        {
            $class1 = ' class="active"';
        }
       
   // echo $sub ->getName().'<br/>';
    echo '<li'.$class1.'><a href="'.$catese.'">◊ '.$sub->getName().'</a></li>';
}
echo '</ul>';
}
else
    {
        echo '<li'.$class.'><a href="'.$cate.'">'.$category->getName().'</a></li>';
       
    }   
 ?>

   <?php endif; ?>
   <?php endforeach; ?>



</ul>
</div>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
   $("li.inactive #show").hide();
   $("li.active #show").show();

    $('#show').click(function(){
    $("li.active #show").slideToggle();
  });
});
</script>

Comments