Magento – How to Get Current Category Filter in Catalog Collection

magento-1.7magento-1.8magento-1.9

<?php
$_category = $this->getCurrentCategory(); $_categoryCollection = Mage::getResourceModel('catalog/category_collection')
                 ->addCategoryFilter($_category)
                 ->addAttributeToSelect('*')
                 ->addAttributeToSelect('is_brand','yes')
                 ->addAttributeToFilter('level','5')
                 ->addIsActiveFilter();
foreach($_categoryCollection as $cat){?>
<ui>
<?php //display current_Category image
     if($cat->getImageUrl()): ?>
      <img src="<?php echo $cat->getImageUrl(); ?>" />
<?php endif; ?>
     <a href="<?php echo $cat->getUrl(); ?>">
<?php //display current_Category image
     echo $cat->getName(); ?>
     </a>
    </ul>
<?php   
        }
        ?>

I want to display categories which have the value "yes" for the category attribute "is_brand". and i want it to be fetched from the current category. I could not access getCurrentCategory() inside catalog/category_collection..

i need only to fetch the category collection of level 5 only in the current category.
THE ABOVE CODE FETCHES COLLECTIONS WITH LEVEL 5 FROM ALL CATEGORIES.

Best Answer

Give this a try:

$_category = $this->getCurrentCategory(); 
$path = $_category->getPath();
$_categoryCollection = Mage::getResourceModel('catalog/category_collection')
             ->addAttributeToFilter('path', array('like' => $path.'/%'))
             ->addAttributeToSelect('*')
             ->addAttributeToFilter('is_brand','1')
             ->addAttributeToFilter('level','5')
             ->addIsActiveFilter();