Accordion Menu for Magento Layered Navigation
jQuery Accordion Menu for Magento Layered Navigation
Layered Navigation is one of the many great features from Magento, its powerful filtering feature can be a great usability enhancement for an eCommerce site. However, if you setup too many product attributes for you store, the Layered Navigation maybe expanded too long and resulting long vertical scrolling for your product listing page and will avert the usability purpose. With this in mind we have implemented Accordion menu for Layered Navigation in all our premium magento themes.
In this Accordion menu we use jQuery script instead of the Accordion that you see in Magento admin and One Page Checkout, the reason for this is because the Accordion menu written by Varien, is not accessible with JS turns off; though we are unable to fix all Magento codes that create obstacle for accessibility, we try hard to make improvement whenever possible.
Ok, off we go…
- Go download jQuery script if you haven’t already done so
- Add jQuery code to “page.xml” file
- Modify “view.phtml” located at template/catalog/layer
Download jQuery Code
We use jQuery 1.2.6 for all our Magento themes and templates. This version is not compatible with Scriptaculous script that comes with each Magento download. You must upgrade your Scriptaculous script to v1.82 or use jQuery 1.2.3 instead.
Put your jQuery file in the “js” folder located in the root (or Magento) directory. We recommend you create a new folder called “jquery”. The Scriptaculous code is also located in “js” folder.
For noConflict part, please refer to this Wiki post for noConfict implementation. If you want to skip reading another article, simple paste this code at the very bottom of your jQuery file.
jQuery.noConflict();
Add jQuery code to “page.xml” file
Add this line of code in your page.xml” file:
Modify “view.phtml” located at template/catalog/layer
In this file you see:
getFilters() ?>
getItemsCount()): ?>
getHtml() ?>
All we need is call the ID, “narrow-by-list”" from jQuery, and add an anchor element in “dt” like so:
Now either place this code directly in “view.phtml” or place it in “head.phtml”. As for the CSS part, because the “narrow-by-list” and its child elements are already existed in the “boxes.css” file, so we will just skip this part.
Now you will have a simple Accordion menu that requires no plugin. You can see the final result from our Courtyard House Furnish theme.
9 Comments to “ Accordion Menu for Magento Layered Navigation ”