It is necessary to add the class .active to the selected item.

In the place where there is a standard menu code:

<?php foreach ($categories as $category) { ?> <?php if ($category['children']) { ?> <li class="dropdown"><a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown"><?php echo $category['name']; ?></a> <div class="dropdown-menu"> <div class="dropdown-inner"> <?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?> <ul class="list-unstyled"> <?php foreach ($children as $child) { ?> <li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li> <?php } ?> </ul> <?php } ?> </div> <a href="<?php echo $category['href']; ?>" class="see-all"><?php echo $text_all; ?> <?php echo $category['name']; ?></a> </div> </li> <?php } else { ?> <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li> <?php } ?> <?php } ?> 

It would be possible to simply add your own code with links instead, but how to make the class .active switch?

  <ul> <li><a href="<?php echo $home; ?>"><?php echo $text_home; ?></a></li> <li><a href="<?php echo $wishlist; ?>" id="wishlist-total"><?php echo $text_wishlist; ?></a></li> <li><a href="<?php echo $account; ?>"><?php echo $text_account; ?></a></li> <li><a href="<?php echo $shopping_cart; ?>"><?php echo $text_shopping_cart; ?></a></li> <li><a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a></li> </ul> 
  • It is necessary to understand what condition applies to the class. Inactive, and prescribe through an if-else. - labris

1 answer 1

A way to menu categories. I describe the case with the default template, in custom builds some points may differ. But if you work with OC - you will understand.

in header.php , in the categories menu forming cycle

 $categories = $this->model_catalog_category->getCategories(0); foreach ($categories as $category) { ... } 

add:

 // провСряСм запрос ΠΊΠ°Ρ‚Π΅Π³ΠΎΡ€ΠΈΠΈ (достаём Π΅Ρ‘ id) // ΠΈ сравниваСм с катСгориями Π² Ρ†ΠΈΠΊΠ»Π΅ наполнСния массива $categories. // Π² случаС совпадСния присваиваСм Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ нСсущСй имя Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠ³ΠΎ класса $class = ''; if(isset($this->request->get['path'])) { if ($category['category_id'] == $this->request->get['path']) { $class = ' top-menu-active'; } } 

and substitute the $class variable in the definition of the category data array:

 // Level 1 $data['categories'][] = array( 'name' => $category['name'], 'children' => $children_data, 'column' => $category['column'] ? $category['column'] : 1, 'href' => $this->url->link('product/category', 'path=' . $category['category_id']), 'class' => $class, // <-- 'image' => $category['image'], 'category_id' => $category['category_id'] ); 

In header.tpl, add the output to the $class variable for the menu item of the menu - category:

 <?php foreach ($categories as $category) { ?> <li class="dropdown<?=$category['class']?>"> .... 

Thus, a custom class will be added to the menu item of the active category.