Magento 1.9 – Fix Layer Navigation Filter Not Working

filterlayered-navigationmagento-1.9

I need to show the layer navigation filter values in above the search page heading.

enter image description here

I have tried below code in the
app\design\frontend\rwd\default\template\catalogsearch\result.phtml
file.

$layout         = Mage::getSingleton('core/layout');
$block_header   = $layout->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state_1.phtml');
$block_links    = $layout->createBlock('core/text_list','catalog.leftnav.state.renderers');
$block_header->setChild('state_renderers',$block_links);
echo $block_header->toHtml();

But I am getting empty value.

Please assist me.

Best Answer

you can get active filter with below code. tested code..

for category page

 <?php 
$_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();

foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter->getRemoveUrl() ?>” title=”<?php echo $this->__('Remove This Item') ?>”><?php echo $this->__('Remove This Item') ?></a>
<?php endforeach; ?>

for search page

    <?php 
 $_filters = Mage::getSingleton('catalogsearch/layer')->getState()->getFilters();

foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter->getRemoveUrl() ?>” title=”<?php echo $this->__('Remove This Item') ?>”><?php echo $this->__('Remove This Item') ?></a>
<?php endforeach; ?>

or you want to show only the current filter state use this code

for category page

<?php echo $this->getLayout()->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state.phtml')->toHtml(); ?>

for search result

<?php echo Mage::app()->getLayout()->createBlock('catalogsearch/layer')->setTemplate('catal‌​og/layer/state.phtml')->toHtml(); ?>
Related Topic