Follow by Email

Tuesday, January 21, 2014

Create Left menu in category page

Please open your template\catalog\navigation\left.phtml
 And wright the following code there.

<?php
$current_category = Mage::registry('current_category');
global $current_category_id;
$current_category_id = $current_category->getId();
if($current_category->getLevel()==2){
?>
<div class="block block-layered-nav">
    <div class="block-content">
    <dl id="narrow-by-list2">
            <dt><?php echo $this->__('Category') ?></dt>
            <dd>
               
                    <?php
                    $rootcatId= Mage::app()->getStore()->getRootCategoryId();
                    $categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
                    function  get_categories($categories,$lvl,$c_cat) {   
                        global $current_category_id;
                        $array= '<ul class="level_'.$lvl;
                        if($lvl>1){                           
                            if($current_category_id!=$c_cat){
                                $array .=' cate" style="display:none">';
                            }else{
                                $array .= ' cate open">';
                            }
                        }else{
                            $array .='">';
                        }
                        foreach($categories as $category) {
                            $cat = Mage::getModel('catalog/category')->load($category->getId());
                            $count = $cat->getProductCount();
                            $array .= '<li>';
                           
                            if($cat->getLevel()==2){
                                if($current_category_id!=$category->getId())
                                    $array .='<span class="slide active2"></span>';
                                else
                                    $array .='<span class="slide active1"></span>';
                            }
                           
                            $array .= '<a href="' . Mage::getUrl($cat->getUrlPath()). '">' .
                                      $category->getName() . "(".$count.")</a>\n";
                            if($category->hasChildren()) {
                                $children = Mage::getModel('catalog/category')->getCategories($category->getId());
                                $levl = $category->getLevel();
                                 $array .=  get_categories($children,$levl,$category->getId());
                                }
                             $array .= '</li>';
                        }
                        return  $array . '</ul>';
                    }
                    echo  get_categories($categories,1,$rootcatId);                    
                    ?>
          </dd>         
    </div>               
</div>
<?php } ?>

<script>
var $js = jQuery.noConflict();
$js(document).ready(function() {
    $js('.slide').click(function(){
        $js('.cate').slideUp(300);
        $js('.slide').removeClass('active1');
        $js('.slide').addClass('active2');
       
        $js(this).next().next().slideDown(300);
        $js(this).removeClass('active2');
        $js(this).addClass('active1');
    });
   
});
</script>

No comments:

Post a Comment