Home Magento Customization

Custom category menu navigation in Magento

26 July 2009 No Comment

Just some code for custom category menu navigation. I’m a bit short on time so, no fancy walk trough. All you need to make this show on your page is to call it inside layout file like

<block type=”core/template” template=”surgeworks/customcatnav.php” />

Filename: customcatnav.php.


<?php
//Get store id
$storeId    = Mage::app()->getStore()->getId();

//Get category model
$_category = Mage::getModel(’catalog/category’)->setStoreId($storeId);

$_categoryCollection = $_category->getCollection();
$_categoryCollectionIds = $_categoryCollection->getAllIds();

//Remove root category from array
unset($_categoryCollectionIds[0], $_categoryCollectionIds[1]);

?>

<div class=”content”>
<?php

$o = null;

$o .= ‘<dl>’;
foreach ($_categoryCollectionIds as $catId)
{
$_category = $_category->load($catId);

if($_category->getLevel() == 2)
{

$catChildren = $_category->getChildren();
if(!empty($catChildren))
{
$o .= ‘<dt>’.$_category->getName().’</dt>’;

$categoryChildren = explode(”,”, $catChildren);

foreach ($categoryChildren as $categoryChildId)
{
/* @var $_childCategory Mage_Catalog_Model_Category */
$_childCategory = $_category = Mage::getModel(’catalog/category’)->setStoreId($storeId)->load($categoryChildId);

$o .= ‘<dd>’;
$o .= ‘<span class=”categoryName”><a href=”‘.$_childCategory->getUrl().’”>’.$_childCategory->getName().’</span class=”totalNumberOfProducts”></a>’;
$o .= ‘<span class=”totalNumberOfProducts”>’.$_childCategory->getProductCollection()->count().’</span>’;
$o .= ‘</dd>’;
}

}

}
}
$o .= ‘</dl>’;

echo $o;

?>
</div><?php //content ?>

By Branko from Activecodeline.com

Related posts:

  1. Custom Category Images Listing Block Tutorial
  2. Some custom Blocks to help you show products
  3. Magento Vertical Category Menu
  4. Tips For Creating Dynamic Category Landing Pages
  5. Magento Navigation, how to customize very helpful information?

Comments are closed.