Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 10
Here is code to control layered navigation
 
Tweakmag
Guru
 
Avatar
Total Posts:  307
Joined:  2007-08-31
London, UK
 

Hi there,
it seems a few people want to control the way layered navigation works, here is some code that will let you:
1. Define any attributes that you want to be displayed as a dropdown list
2. Set a threshold limit for the attributes, so that if this threshold is met, then automatically display as a dropdown list

This code needs to go into “app/design/frontend/default/[YOURTHEME]/template/catalog/layer/filter.phtml

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * 
 */

/**
 * Template for filter items block
 * Coded by Adam Martin (www.tweakmag.com)
 * 
 * 
 * @see Mage_Catalog_Block_Layer_Filter
 */
?>

<?php
    
//control the way that the layered navigation attributes present themselves
    //either dropdown list or default methd (ordered list)
    
$attributeName $this->getName();
    
$itemcountthreshold 2// you can change this
    
$itemcount $this->getItemsCount();
    
$displayitemcount false//set to true/false to display item count in brackets
    
    
    
if($itemcount $itemcountthreshold){
        $attributeName 
"Overthreshold";
    
}
    
    
if(!function_exists("_displayOrderedlist")){
        
function _displayOrderedlist($atts,$displayitemcount){
            
echo '<ol>';
            foreach(
$atts->getItems() as $_item){
                
echo '<li><a href="'.$_item->getUrl().'">'.$_item->getLabel().'</a>';
                if(
$displayitemcount){
                    
echo ' ('.$_item->getCount().')';
                
}
                
echo '</li>';
            
}
            
echo '</ol>';
        
}
    }
    
if(!function_exists("_displayDropdown")){
        
function _displayDropdown($atts,$displayitemcount){
            
echo '<select id="layered-select" class="select" name="layered-select" onchange="if (this.selectedIndex > 0) location.href=this[this.selectedIndex].value;">';
            echo 
'<option selected="selected">Please select</option>';
            foreach (
$atts->getItems() as $_item){
                
echo '<option value="'.$_item->getUrl().'">';
                echo 
$_item->getLabel();
                if(
$displayitemcount){
                    
echo ' ('.$_item->getCount().')';
                
}
                
echo '</option>';
            
}
            
echo '</select>';
        
}
    }
    
    
switch ($attributeName{
        
case 'Shoe Size':
        case 
'Overthreshold':
            
_displayDropdown($this,$displayitemcount);
            break;
    
        default:
            
_displayOrderedlist($this,$displayitemcount);
            break;
    
}    
    
?>

You will see that I have added case ‘Shoe Size’ - by doing this anytime the Shoe Size attribute is displayed it will be displayed using a dropdown. For example you could add:

case 'Price':
to make price always display as a dropdown.

Cheers
Adam

Image Attachments
layerednav.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

Thank you! I am gonna to try it out smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
shd-media
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2008-03-15
 

thank you very much. Is there any way to show the points next each other? I will display them next each other above the products…

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

@Ajazza ;

Thank you for that…
Works 100%

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

@Ajazza ;

just wondering.

When it comes to price, is it posable to let the user enter an amount and not a predefined one form the system?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

Hi Adam,

Your code works really well and I absolutely love, however I’d just realized it disables the ‘count item’.

Please see attached screenshots. T

Image Attachments
lnav.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
Tweakmag
Guru
 
Avatar
Total Posts:  307
Joined:  2007-08-31
London, UK
 

Hi chinesedream - I programmed it so you can turn this on or off yourself.

displayitemcount false//set to true/false to display item count in brackets

Too easy aye smile
I will package this up as an extension soon - so then it will work on all themes
Cheers
Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tweakmag
Guru
 
Avatar
Total Posts:  307
Joined:  2007-08-31
London, UK
 

@Ajazza ;

just wondering.

When it comes to price, is it posable to let the user enter an amount and not a predefined one form the system?

I am sorry, I am not sure what you mean

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 
Ajazza - 09 April 2008 05:07 PM

Hi chinesedream - I programmed it so you can turn this on or off yourself.

displayitemcount false//set to true/false to display item count in brackets

Too easy aye smile
I will package this up as an extension soon - so then it will work on all themes
Cheers
Adam

Ah yes, see it now. Thank you so much smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
glaDiator
Member
 
Avatar
Total Posts:  65
Joined:  2008-03-17
 

I am also going to give it a try............... cool smirk

 
Magento Community Magento Community
Magento Community
Magento Community
 
Danielc1234
Sr. Member
 
Avatar
Total Posts:  175
Joined:  2008-01-09
Miami, FL - United States
 

@Ajazza ;
Nice work. Do you know if this will work with the final release 1.0? And can you tell me how to impliment this on the home page? We are trying to put a full category menu on the left side of all our pages? Any help would be greatly appreciated. Looks like you have this Magento under control!!!
Thanks in advance. Daniel

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tweakmag
Guru
 
Avatar
Total Posts:  307
Joined:  2007-08-31
London, UK
 

The code I posted works on v1.0 no problems at all. Regarding your other question about having the layered navigation on the home page - I am not 100% sure how you would go about that as the navigation is built by looking at the products / categories within the category you are viewing - homepage is not a category as such, so there is no navigation to be built. So what category would you want the layered navigation to be built from?

Cheers
Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
Danielc1234
Sr. Member
 
Avatar
Total Posts:  175
Joined:  2008-01-09
Miami, FL - United States
 

How would I go about hard coding the categorys? I have already set up a <div> that contains all my categories the way I want them laid out. How could I just drop that on the left column of the home page?
I know hard coding is not the way to go, but chances are my categories, once set will not change.
Thanks
Daniel

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tweakmag
Guru
 
Avatar
Total Posts:  307
Joined:  2007-08-31
London, UK
 

I have done the same thing on julesroc.com.au (we are currently upgrading to 1.0 at the moment). But what we did was created a new template just for the homepage that was based on the 3 columns and hardcoded the categories in. This is one approach, another is to write some xml that updates the template and inserts your phtml file that contains your customer code for linking to the categories.

I hope this helps, if you can’t follow what i said - please let me know, and I will see if I can help further tomorrow smile
Cheers
Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
AnnaM
Guru
 
Avatar
Total Posts:  325
Joined:  2008-01-29
San Francisco
 

Thats terrific! I have not tried it out yet, but from the sounds of others, its working great. Just wanted to say mucho thanks ahead of time!  Very cool.  wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tweakmag
Guru
 
Avatar
Total Posts:  307
Joined:  2007-08-31
London, UK
 

Thanks Anna smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 10