Expanding Left Hand Category Menu in Magento

The below code will create a menu that shows the siblings of an active category as well as showing its grandchildren. This will allow a user to jump between categories easily. Active classes are provided and the parent category is used to create a title. Again I am not a PHP developer so any bug fixes or tips are welcome.

Modify app/design/frontend/YOUR THEME/default/template/catalog/navigation/left.phtml to contain:

<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php $categoriescount = $this->getStoreCategories()->count();?>
 
<div class="block block-layered-nav">
<?php 
//If there are any root categories
if ($categoriescount > 0): 
	foreach($categories as $category): 
		//Get sub categories 
		$subcategories = $category->getChildren();
		//Number of sub categories
		$subcategoriescount = $category->getChildren()->count(); 
		// Display active root category as block title only if there are sub categories
		if ($this->isCategoryActive($category) && $subcategoriescount > 0): 
?>
		<div class="block-title">
		<a href="<?php echo $helper->getCategoryUrl($category) ?>">
			<strong><span><?php echo $this->escapeHtml($category->getName()) ?></span></strong>
		</a>
		</div>
		<div class="block-content">
			<ul class="level1">
				<?php 
				//Build sub category menu
				foreach($subcategories as $subcategory): 
					//Get sub sub categories
					$subsubcategories = $subcategory->getChildren();
					//Number of sub sub categories
					$subsubcategoriescount = $subcategory->getChildren()->count();?>
 
					<li class="level1<?php if($subsubcategoriescount > 0): ?> parent<?php endif; ?>">
					<a href="<?php echo $helper->getCategoryUrl($subcategory) ?>" <?php if ($this->isCategoryActive($subcategory)): ?>class="active"<?php endif; ?>><?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a>
					<?php 
					//Display sub sub categories if sub category is active
					if ($this->isCategoryActive($subcategory) && $subsubcategoriescount > 0): 
					?>
						<ul class="level2">
							<?php foreach($subsubcategories as $subsubcategory): ?>
							<li class="level2">
								<a href="<?php echo $helper->getCategoryUrl($subsubcategory) ?>" <?php if ($this->isCategoryActive($subsubcategory)): ?>class="active"<?php endif; ?>><?php echo $this->escapeHtml(trim($subsubcategory->getName(), '- ')) ?></a>
							</li>
							<?php endforeach; ?>
						</ul>
					<?php endif; ?>
				</li>
				<?php endforeach; ?>
			</ul>
		</div>
		<?php endif; ?>
	<?php endforeach; ?>
<?php endif; ?>
</div>

See below for a quick wirefame mockup of how it should look:
nav

Displaying Sub Categories on Category Landing Page in Magento

The below code snippet/instructions will display images and links for each sub category on a category landing page. Feel free to use this code as a reference, however not being a PHP developer there may well be errors so I welcome any tips or improvements!

1. Create a new file called “categoryblocks.phtml” in app/design/frontend/YOUR THEME/default/template/catalog/navigation

2. Paste the following code into it and save:

<?php 
//If there are sub categories
$categories = $this->getCurrentChildCategories();
$categoriescount = $this->getCurrentChildCategories()->count();
if ($categoriescount > 0): 
?>
<div class="sub-category-container">	
	<?php 
	//Loop through categories
	foreach ($categories as $category):
	?>
	<div class="sub-category">
		<a href="<?php echo $this->getCategoryUrl($category)?>" class="cat-image">
		<?php 
		// If there is a thumbnail set for the category - Display it
		if($imgUrl = Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()):?>
		<img src="<?php echo $this->getBaseUrl()."media/catalog/category/".$imgUrl ?>" width="220" height="110" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
		<?php endif; ?>
		</a>
		<div class="inner-sub-category">
			<a href="<?php echo $this->getCategoryUrl($category)?>" class="sub-link"><?php echo $category->getName()?></a>
			<a href="<?php echo $this->getCategoryUrl($category)?>" class="btn"><span>View All</span></a>
		</div>
	</div>
 
	<?php endforeach; ?>
</div>
<?php else:?>
<p>No Sub Categories</p>
<?php endif; ?>

3.Create a static block in Magento Admin called “categorylanding”

4.Place the following code snippet into the static block and save.

{{block type="catalog/navigation" template="catalog/navigation/categoryblocks.phtml"}}

5. Go to Manage Categories in Magento Admin and select “categorylanding” as a static block for the categories you wish to display sub categories for.

This should generate something like this:

category-blocks

You can style however you want using the classes provided or by editing to suit your requirements.