Multi language Image Rollover menu in Magento 1.3.0

Last modified by superseostar on Thu, February 2, 2012 01:24
Source|Old Revisions  

This is an old revision of the document!


Introduction

Hello everyone. I’m Tim van de Velde from the Netherlands. I would like to contribute my findings to the magento community.

It has been a long journey searching for the right solution to display rollover image buttons in the magento catalog menu. First I’ve gotten the right result using this wiki: create_a_top_image_menu, adding some variable css, but it wasn’t upgrade proof. So I decided to make my own workaround.

This solution is not 100% clean-coded, as i’m not a programmer but a designer. But it works ! If anyone has any better ideas to make the code cleaner, please do.

Here is an example of what i’ve come up to till now: http://www.secuprogov.com/magento/

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

1. EDITING THE CORE

1.1 BACKUP BACKUP !

Before you start: everything that is edited in the core, will be overwritten when upgrading. So backup your edited files before you upgrade in the future.

1.2 Editing: Navigation.php

The only file you need to edit is: Navigation.php. The file can be found in /app/code/core/Mage/Catalog/Block/ Make a backup of the original Navigation.php. For obvious reason to set things back if it fails.

Now i’ll try to explain what I did, so you understand what happens if you change the code.

1.2.1 Getting grip on the css classes

The button is made out of css backgrounds, and a transparent gif/png for the <a href> clickable area. The magento catalog puts out a nearly unusable css class system. Because if you edit level 0, all the other levels get the same changes. This makes it impossible to make image backgrounds.

The following edit, tells magento to only put the word “parent” BEFORE the level 0 class, instead of AFTER. This way you can control the level 0 CSS separately. After that i’ve changed the url path to category name, in the class. Because urls are not multilingual, and category names are.

OLD CODE:
      $html.= ' class="level'.$level;
      $html.= ' nav-'.str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath()));
      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";
NEW CODE:
      $html.= ' class="';
      if ($hasChildren) {
          $cnt = 0;
          foreach ($children as $child) {
              if ($child->getIsActive()) {
                  $cnt++;
              }
          }
          $html .= ' parent';
      }
      $html.= '-nav-'.$this->htmlEscape($category->getName()).'';
      $html.= '">'."n";
OUTPUT for level 0

was: <li class=”level0 nav-categoryname parent”

now: <li class=”parent-nav-categoryname”

1.2.2 Adding the transparant gif to Level 0

OLD CODE:
      $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."n";
NEW CODE:
          $html.= '<a href="'.$this->getCategoryUrl($category).'">';
       if ($hasChildren) {
          $cnt = 0;
          foreach ($children as $child) {
              if ($child->getIsActive()) {
                  $cnt++;
              }
          }
          $html.= '<img style="float: left;" src="/magento/skin/frontend/yourtheme/yourskin/images/press/'.$this->htmlEscape($category->getName()).'.gif" border="0">'."n";
      }
      $html.= '<span>'.$this->htmlEscape($category->getName()).'</span></a>'."n";
OUTPUT for level 0

was: <a href=”website-url/category”><span>Categoryname</span></a>

now: <a href=”website-url/category”><img src=”/magento/skin/frontend/yourtheme/yourskin/images/press/Categoryname.gif” border=”0”></a>

   <a href="website-url/category"><span>Categoryname</span></a>
      

It places the transparent gif before the posted text. We will hide the text in level 0 using css. → Of course nothing is shown yet, because the css hasn’t been adjusted yet.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

2. ADDING THE IMAGES & CSS

2.1 Adding the images

First thing is: knowing how you want the final design to be. Every button consists of three images. And for each extra language you need another three images.

Place the images of your button in the images/ folder of your theme.

  1. images/topmenu/Categoryname.gif = standard graphic
  2. images/topmenu/Categoryname-hover.gif = mouseover graphic
  3. images/press/Categoryname.gif = area to click / mouseover

As you can see i’ve added some folders in the images path, just to keep things tidy. All the images need to be the same size (of course)

2.2 Editing: menu.css

Now we’ll add the css for each button you want to create. LEAVE the 0 LEVEL Css as it is. Just add css code under existing code.

Original Level 0 css:

  /************ 0 LEVEL  ***************/
  #nav li { float:left; }
  #nav li.active a { color:#d96708; }
  #nav a { float:left; padding:5px 12px 6px 8px; font-weight:bold; color:#a7c6dd; }
  #nav li.over a,
  #nav a:hover { color:#d96708; }

Adding category Level 0 css:

As shown below, I’ve added a css background for the button, and another css background for the mouse-over. The press image is loaded by Navigation.php. In the first line, you enter the width and height of the actual image. And other style options such as borders/background colors and more.

IMPORTANT: I’ve hidden the posted category text in level 0 by setting the font-size to 0px. Please change for other solution?

  /************ CATEGORY NAME  ***************/
  #nav li.parent-nav-Categoryname { width: 200px; height: 50px; font-size: 0px; float:left; border-right: 1px solid #black; background: url('../images/topmenu/Categoryname.gif') no-repeat;}
  #nav li.parent-nav-Categoryname.active a {}
  #nav parent-nav-Categoryname a {}
  #nav li.parent-nav-Categoryname.over { background: url('../images/topmenu/Categoryname-hover.gif') no-repeat;}
  #nav parent-nav-Categoryname a:hover {}

Changing other levels css to ignore level 0 changes:

OLD:
  
  /************ 1ST LEVEL ************/
  #nav ul li,
  #nav ul li.active { float:none; margin:0; padding-bottom:1px; background:#ecf3f6 url(../images/nav_divider.gif) repeat-x 0 100%; }
  /*#nav ul li.over { background:#d5e4eb url(../images/nav_divider.gif) repeat-x 0 100%; }*/
  #nav ul li.last { background:#ecf3f6; padding-bottom:0; }
  #nav ul a,
  #nav ul a:hover { float:none; padding:0; background:none; }
  #nav ul li a { font-weight:normal !important; }
  /************ 2ND LEVEL ************/
  #nav ul { position:absolute; width:15em; top:25px; left:-10000px; border:1px solid #899ba5; }
  /* Show menu */
  #nav li.over > ul { left:0; }
  #nav li.over > ul li.over > ul { left:100px; }
  #nav li.over ul ul { left:-10000px; }
  #nav ul li a { background:#ecf3f6; }
  #nav ul li a:hover { background-color:#d5e4eb; }
  #nav ul li a,
  #nav ul li a:hover { color:#2f2f2f !important; }
  #nav ul span, #nav ul li.last li span { padding:3px 15px 4px 15px;}
  /************ 3RD+ LEVEL ************/
  #nav ul ul { top:5px; }
NEW:
  /************ 1ST LEVEL ************/
  #nav ul li { width: 190px; height: 23px; font-size: 12px !important; float:none; padding: 0px 0px 1px 0px !important; margin:0; padding-bottom:1px; background:#ecf3f6 url(../images/nav_divider.gif) repeat-x 0 100%; }
  #nav ul li.active { float:none; padding: 0px 0px 1px 0px !important; margin:0; padding-bottom:1px; background:#dcf3f6 url(../images/nav_divider.gif) repeat-x 0 100%; }
  #nav ul li.over { width: 190px; height: 23px; font-size: 12px !important; float:none; padding: 0px 0px 1px 0px !important; margin:0; padding-bottom:1px; background:#ecf3f6 url(../images/nav_divider.gif) repeat-x 0 100% !important; }
  #nav ul li.last { background:#e0e0e0; padding-bottom:0; }
  #nav ul a,
  #nav ul a:hover { float:none !important; padding:0; background: none !important; }
  #nav ul li a { font-weight:normal !important; }
  /************ 2ND LEVEL ************/
  #nav ul { position:absolute; width:15em; top:56px; left:-10000px; border:1px solid #555; }
  /* Show menu */
  #nav li.over > ul { left:0; }
  #nav li.over > ul li.over > ul { left:100px; }
  #nav li.over ul ul { left:-10000px; }
  #nav ul li a { background:#ecf3f6 !important; }
  #nav ul li a:hover { background:#d5e4eb !important; }
  #nav ul li a,
  #nav ul li a:hover { color:#2f2f2f !important; }
  #nav ul span, #nav ul li.last li span { padding:3px 15px 4px 15px;}
  /************ 3RD+ LEVEL ************/
  #nav ul ul { top:5px; }

2.3 More buttons / languages

The files are now shown by Categoryname. So repeat the steps 2.1 and 2.2 for each category, and for each language. For example:

English Category images:

  1. images/topmenu/Furniture.gif
  2. images/topmenu/Furniture-hover.gif
  3. images/press/Furniture.gif

Dutch Category images:

  1. images/topmenu/Meubels.gif
  2. images/topmenu/Meubels-hover.gif
  3. images/press/Meubels.gif

English Category CSS:

  /************ FURNITURE  ***************/
  #nav li.parent-nav-Furniture { width: 200px; height: 50px; font-size: 0px; float:left; border-right: 1px solid #black; background: url('../images/topmenu/Furniture.gif') no-repeat;}
  #nav li.parent-nav-Furniture.active a {}
  #nav parent-nav-Furniture a {}
  #nav li.parent-nav-Furniture.over { background: url('../images/topmenu/Furniture-hover.gif') no-repeat;}
  #nav parent-nav-Furniture a:hover {}

Dutch Category CSS:

  /************ MEUBELS  ***************/
  #nav li.parent-nav-Meubels { width: 200px; height: 50px; font-size: 0px; float:left; border-right: 1px solid #black; background: url('../images/topmenu/Meubels.gif') no-repeat;}
  #nav li.parent-nav-Meubels.active a {}
  #nav parent-nav-Meubels a {}
  #nav li.parent-nav-Meubels.over { background: url('../images/topmenu/Meubels-hover.gif') no-repeat;}
  #nav parent-nav-Meubels a:hover {}
  

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

3. NOW IT SHOULD WORK

If the images are placed in the correct place, and all the links are correct, your rollover menu should work now. The only limitations now, are design-limitations. * http://www.nhakhoavietgiao.com.vn/list2.php?cid=49 nha khoa * http://www.cuudulieu24h.com cuu du lieu http://www.digiseo.com/gioi-thieu.php quang cao truc tuyen

http://www.digiseo.com seo http://banbuon24h.com rao vat http://www.digiseo.com/en seo services http://www.digiseo.com/thiet-ke-website thiet ke web http://www.digiseo.com/quang-ba-website quang ba web http://www.digiseo.com/quang-ba-website/dich-vu-seo.php marketing online http://www.sms4smile.org Funny SMS * http://thutucthanhlapcongty.net/index.php/doanh-nghiep-trong-nuoc/thanh-lap-cong-ty-tnhh-mot-thanh-vien/ thanh lap cong ty * http://uvc-thanhlapcongty.com thanh lap cong ty * http://uvc-thanhlapcongty.com thanh lap cty * http://uvc-thanhlapcongty.com thành lập công ty * http://uvc-thanhlapcongty.com/dang-ky-online/dang-ky-thanh-lap-doanh-nghiep.html thanh lap doanh nghiep * http://uvc-thanhlapcongty.com/dang-ky-online/dang-ky-thanh-lap-doanh-nghiep.html thành lập doanh nghiệp * http://uvc-thanhlapcongty.com/dang-ky-online/dang-ky-thanh-lap-doanh-nghiep.html dang ky kinh doanh * http://uvc-thanhlapcongty.com/cung-cap-dich-vu/dich-vu-ke-toan.html dich vu ke toan * http://uvc-thanhlapcongty.com/cung-cap-dich-vu/dich-vu-ke-toan.html dịch vụ kế toán * http://uvc-thanhlapcongty.com/cung-cap-dich-vu/dai-ly-bao-cao-thue.html bao cao thue * http://uvc-thanhlapcongty.com/van-ban-phap-quy/dang-ky-kinh-doanh.html dang ky kinh doanh http://namthaibinhduong.edu.vn tu van du hoc

Troubleshooting

I’ve tested only in FF 3.# and IE 7#. And safari mobile (iphone) No other browsers tested.

Use firefox + firebug to check your code, if it calls to other file locations and/or wrong css classes: adjust the css code to the output from magento. You can find my contact details on my profile page. Please feel free to contact me if something doesn’t work out.

Questions can be asked here: http://www.magentocommerce.com/boards/viewthread/38186/ forex trading robots

Enjoy !

Tim van de Velde




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs