1

I am trying to get applied active filters on layered navigation. Below is my code which i had tried:-

<?php $r = new Mage_Catalog_Block_Layer_State(); ?>
<?php $_filters = $r->getActiveFilters(); ?>
<ul class="tool-result">
    <?php foreach ($_filters as $_filter):?>
        <li>
            <?php if ($_filter->hasData('children')): ?>
                <?php foreach ($_filter->getData('children') as $child): ?>
                    <a href="<?php echo $child['url'] ?>"><?php echo $child['label'] ?>&nbsp;<span>&times;</span></a>
                <?php endforeach ?>
            <?php else: ?>
                <a href="<?php echo $_filter->getRemoveUrl() ?>" ?>><?php echo $_filter->getLabel() ?>&nbsp;<span>&times;</span></a>
            <?php endif ?>
        </li>
    <?php endforeach; ?>
</ul>

this code is working on the category page with layered navigation

and this code is not working on the cms page with the layered navigation

2
  • Could you tell us in which block/template you're trying to add this code? It would help with determining what would be the best solution. I'm guessing $r is returning either null or an empty object, because you're not in the right context.
    – Niels
    Mar 7, 2016 at 11:05
  • my this code is in the header.phtml page Mar 7, 2016 at 11:13

1 Answer 1

2

$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();

and you get fetch like that

foreach ($appliedFilters as $item) {
    $item->getName(); // Name of the filter
    $item->getLabel(); // Currently selected value
    $item->getFilter()->getRequestVar(); // Filter code (usually attribute code, except category filter, where it equals "cat")
}

reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.