Filter sub-categories like in layered navigation
Posted
by russjman
on Stack Overflow
See other posts from Stack Overflow
or by russjman
Published on 2010-04-08T21:38:24Z
Indexed on
2010/04/08
21:43 UTC
Read the original article
Hit count: 273
I created a new template file catalog/category/list.phtml. This is to display all sub categories of the current category. I have layered navigation which is displaying sub-categories as one of the filters, but I want this new template to work with these filters as well. Right now when i click the subcategory filter, it filters all products on the page, but still displays all categories of the parent category. $_filters is how i am trying to access these filters, but i get nothing. Is there something i am not initializing correctly to have access to these filters from the layered navigation.
<?php
$_helper = $this->helper('catalog/output');
$_filters = $this->getActiveFilters();
echo $_filters;
if (!Mage::registry('current_category')) return ?>
<?php $_categories=$this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<?php
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$_imgHtml = '';
if ($_imgUrl = $this->getCurrentCategory()->getImageUrl()) {
$_imgHtml = '<img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" class="category-image" />';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
echo $_category->getImageUrl();
?>
<div class="category-image-box">
<div class="category-description clearfix" >
<div class="category-description-textbox" >
<h2><span><?php echo $this->htmlEscape($_category->getName()) ?></span></h2>
<p><?php echo $this->getCurrentCategory()->getDescription() ?></p>
</div>
<a href="<?php echo $this->getCategoryUrl($_category) ?>" class="collection-link<?php if ($this->isCategoryActive($_category)): ?> active<?php endif ?>" >See Entire Collection</a>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"><?php if($_imgUrl): ?><?php echo $_imgHtml ?><?php else: ?><img src="/store/skin/frontend/default/patio_theme/images/category-photo.jpg" class="category-image" alt="collection" /><?php endif; ?></a>
</div>
<?php echo '<pre>'.print_r($_category->getData()).'</pre>';?>
</div>
<?php endif; ?>
<?php endforeach ?>
<?php endif; ?>
© Stack Overflow or respective owner