Hide navigation items with CSS
This is an old revision of the document!
I made a small modification on method drawItem(). The rendered source will give out an individual id for each point in navigation, so this is a small hide-by-css hack.
app/code/core/Mage/Catalog/Block/Navigation.php, around Line 134
Replace
- /**
- * Enter description here...
- *
- * @param Mage_Catalog_Model_Category $category
- * @param int $level
- * @param boolean $last
- * @return string
- */
- public function drawItem($category, $level=0, $last=false)
- {
- $html = '';
- if (!$category->getIsActive()) {
- return $html;
- }
- $children = $category->getChildren();
- $hasChildren = $children && $children->count();
- $html.= '<li';
- if ($hasChildren) {
- $html.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"';
- }
- $html.= ' class="level'.$level;
- if ($this->isCategoryActive($category)) {
- $html.= ' active';
- }
- if ($last) {
- $html .= ' last';
- }
- if ($hasChildren) {
- $cnt = 0;
- foreach ($children as $child) {
- if ($child->getIsActive()) {
- $cnt++;
- }
- }
- $html .= ' parent';
- }
- $html.= '">'."n";
- $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$category->getName().'</span></a>'."n";
- //$html.= '<span>'.$level.'</span>';
- if ($hasChildren){
- $j = 0;
- $htmlChildren = '';
- foreach ($children as $child) {
- if ($child->getIsActive()) {
- $htmlChildren.= $this->drawItem($child, $level+1, ++$j >= $cnt);
- }
- }
- if (!empty($htmlChildren)) {
- $html.= '<ul class="level' . $level . '">'."n"
- .$htmlChildren
- .'</ul>';
- }
- }
- $html.= '</li>'."n";
- return $html;
- }
With
- /**
- * Enter description here...
- *
- * @param Mage_Catalog_Model_Category $category
- * @param int $level
- * @param boolean $last
- * @return string
- * modified for css hide by jan212@05.05.2008
- */
- public function drawItem($category, $level=0, $last=false)
- {
- $html = '';
- if (!$category->getIsActive()) {
- return $html;
- }
- $children = $category->getChildren();
- $hasChildren = $children && $children->count();
- $html.= '<li';
- if ($hasChildren) {
- $html.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"';
- }
- //modified for css hide from jan212
- $cid = $category->getID();
- //
- $html.= ' class="level'.$level;
- //
- if ($this->isCategoryActive($category)) {
- $html.= ' active ';
- }
- if ($last) {
- $html .= ' last';
- }
- if ($hasChildren) {
- $cnt = 0;
- foreach ($children as $child) {
- if ($child->getIsActive()) {
- $cnt++;
- }
- }
- $html .= ' parent';
- }
- //modified for css hide from jan212
- $html.= '" id="nav-'.$level.'-'.$cid.'">'."n";
- //
- $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."n";
- //$html.= '<span>'.$level.'</span>';
- if ($hasChildren){
- $j = 0;
- $htmlChildren = '';
- foreach ($children as $child) {
- if ($child->getIsActive()) {
- $htmlChildren.= $this->drawItem($child, $level+1, ++$j >= $cnt);
- }
- }
- if (!empty($htmlChildren)) {
- $html.= '<ul class="level' . $level . '">'."n"
- .$htmlChildren
- .'</ul>';
- }
- }
- $html.= '</li>'."n";
- return $html;
- }
No you’ll see e.g. something like
- <li class="level0" id="nav-0-5">
in the rendered source of your page menu, e.g. for category 5 like above. The id is based on the following sheme: nav(prefix)-x(Level)-xxxx(Unique Category ID) and inserted to every <li> point.
To hide the navigation entry (for human eyes only) simply create new entries in menu.css like this
- /* css hide from horizontal navigation */
- #nav-0-5 {display:none;} /*examples hides category 5 @ level 0 */
- #nav-1-6 {display:none;} /*examples hides category 6 @ level 1*/
Remember: Every ID is unique
Regards Jan Fervers

