Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To make Custom Top Category Menu Till 3 Levels In Magento
02-28-2013, 06:02 PM (This post was last modified: 08-01-2013 10:30 AM by programmer.)
Post: #1
 

How To make Custom Top Category Menu Till 3 Levels In Magento

We can easily make 3 level categogry navigation and customized according our requirement.

PHP Code:
<?php $_helper Mage::helper('catalog/category'?>
<?php $_categories 
$_helper->getStoreCategories() ?>
<?php $currentCategory 
Mage::registry('current_category'?>



<div class="nav-container<?php if($navCssClasses) echo $navCssClasses?>">
<div class="nav">
<div class="navbar-bg navbar-left"></div>
<div class="navbar-bg navbar">
<ul id="nav">
<?php
$i
=1;
foreach(
$_categories as $_category):
if(
$i<5):
?>
<?php $_category_count 
Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories 
$_category_count->getChildrenCategories() ?>
<?php 
if (count($_subcategories) > 0): 
$class='parent';
else:
$class='';
endif; 
?>

<?php if (!in_array($_category->getId(), $removed_cat_array)) : ?>
<li class="level0 nav-<?php echo $i?> first level-top <?php echo $class?>">
<a class="level-top" href="<?php echo $_helper->getCategoryUrl($_category?>">
<span><?php echo $_category->getName() ?></span>
</a>

<!-- Level 1st Start -->
<?php $_category Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories 
$_category->getChildrenCategories() ?>
<?php 
if (count($_subcategories) > 0): ?>
<ul class="level0">
<?php 
$j
=1;
foreach(
$_subcategories as $_subcategory): ?>
<li class="level1 nav-<?php echo $i?>-<?php echo $j?> <?php if($j==1): echo 'first'; endif; ?>">
<a href="<?php echo $_helper->getCategoryUrl($_subcategory?>">
<span><?php echo $_subcategory->getName() ?></span>
</a>
<!-- Level 1st End -->

<!-- Level 2nd Start -->
<?php $_category2 Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>
<?php $_subcategories2 
$_category2->getChildrenCategories() ?>
<?php 
if (count($_subcategories2) > 0): ?>
<ul class="level1">
<?php 
$k
=1;
foreach(
$_subcategories2 as $_subcategory2): ?>
<li class="level2 nav-<?php echo $i?>-<?php echo $j?>-<?php echo $k?> <?php if($k==1): echo 'first'; endif; ?>">
<a href="<?php echo $_helper->getCategoryUrl($_subcategory2?>">
<span><?php echo $_subcategory2->getName() ?></span>
</a>
</li>
<?php
$k
++;
endforeach; 
?>
</ul>
<?php endif; ?>
<!-- Level 2nd End -->

</li>
<?php
$j
++;
endforeach; 
?>
</ul>
<?php endif; ?>
</li>
<?php 
$i
++;
endif;
endif;
endforeach; 
?>


<!-- MORE Menu Start -->

<li class="nav-custom-link level0 level-top parent">

<a class="level-top" href="#"><span>MORE</span></a>
<ul class="level0">

<?php
$i
=1;
foreach(
$_categories as $_category):
if(
$i>4):
?>
<?php $_category_count 
Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories 
$_category_count->getChildrenCategories() ?>
<?php 
if (count($_subcategories) > 0): 
$class='parent';
else:
$class='';
endif; 
?>

<?php if (!in_array($_category->getId(), $removed_cat_array)) : ?>
<li class="level1 nav-<?php echo $i?> first level-top <?php echo $class?>">
<a class="level-top" href="<?php echo $_helper->getCategoryUrl($_category?>">
<span><?php echo $_category->getName() ?></span>
</a>

<!-- Level 1st Start -->
<?php $_category Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories 
$_category->getChildrenCategories() ?>
<?php 
if (count($_subcategories) > 0): ?>
<ul class="level1">
<?php 
$j
=1;
foreach(
$_subcategories as $_subcategory): ?>
<li class="level2 nav-<?php echo $i?>-<?php echo $j?> <?php if($j==1): echo 'first'; endif; ?>">
<a href="<?php echo $_helper->getCategoryUrl($_subcategory?>">
<span><?php echo $_subcategory->getName() ?></span>
</a>
<!-- Level 1st End -->




</li>
<?php
$j
++;
endforeach; 
?>
</ul>
<?php endif; ?>
</li>
<?php 
endif;
endif;
$i++;
endforeach; 
?>
</ul>
</li>    

<!-- MORE Menu End -->    

</ul>
</div>
<div class="navbar-bg navbar-right"></div>

</div>
</div> 
Quote


Forum Jump:


User(s) browsing this thread: 1 Guest(s)