Joomla! Discussion Forums



It is currently Thu Nov 26, 2009 12:57 pm (All times are UTC )

 


Forum rules

Please submit all new Tips and Tricks to: http://docs.joomla.org/Category:Tips_and_tricks



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
Posted: Sun Mar 23, 2008 12:08 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Tue Mar 18, 2008 4:59 pm
Posts: 7
Ok, I wondered why it's not possible to create an "images only" menu in Joomla. While searching the forums I found this original post by mSalcher.

His solution adds an additional parameter "Menu Icon Link" to the menu module. If this parameteris set and an image has been selected for a menu item then this item will be displayed without text as "image only".

Here are the changes to be made to get this working in "legacy mode":

/modules/mod_mainmenu/legacy.php line 144:
Code:
code to be replaced:
if ($params->get('menu_images'))
   {
      $menu_params = new stdClass();
      $menu_params = new JParameter($mitem->params);

      $menu_image = $menu_params->def('menu_image', -1);
      if (($menu_image <> '-1') && $menu_image) {
         $image = '<img src="'.JURI::base(true).'/images/stories/' . $menu_image . '" border="0" alt="' . $mitem->name . '"/>';
         
         if( $params->get('menu_images_link') ){
            $txt = '<a href="'.$mitem->url.'" class="'.$menuclass.'" '.$id.'>'.$image.'</a>';
         } else {
           if ($params->get('menu_images_align')) {
              $txt = $txt . ' ' . $image;
           } else {
              $txt = $image . ' ' . $txt;
           }
          }
      }
   }


/modules/mod_mainmenu/mod_mainmenu.php line 41:
Code:
code to be added:
$params->def('menu_images_link', 0);


/modules/mod_mainmenu/mod_mainmenu.xml line 58:
Code:
code to be added:
   <param name="menu_images_link" type="radio" default="0" label="Menu Icon Link" description="Link on Images Instead of Text">
          <option value="0">No</option>
      <option value="1">Yes</option>
   </param>


I wanted to get this working in "non legacy mode" so I made these additional two changes:

change in modules/mod_mainmenu/helper.php line 51:
Code:
if (array_key_exists($row->parent, $ids)) {
add 1 line:
                $row->ionly = $params->get('menu_images_link');
                $menu->addNode($row);


line 295:
Code:
if ($iParams->get('menu_image') && $iParams->get('menu_image') != -1) {
         $image = '<img src="'.JURI::base(true).'/images/stories/'.$iParams->get('menu_image').'" alt="" />';
add 3 lines:
         if($tmp->ionly){
            $tmp->name = null;
         }
      } else {
         $image = null;
      }



That's it.

And here's a way to get an real rollover image - css only - menu with this solution. Make the changes above and enable the new parameter for your menu module. Then upload a blank 1x1 pixel gif file to your images/stories folder and select this blank image as menu image for your menu items.

Now your menu appears empty because your itmes are displayed as 1x1 transparent gifs only. Now go to the template.css and define the "real" images as background images for your items.

Here's an example:

First the general setings for this menu:
Code:
/* horizontal top menu */
#topmenu {
  white-space: nowrap;
  height: 32px;
  float: right;
  vertical-align: top;
  margin-top: 14px;
}

#topmenu ul {
  margin: 0;
  padding: 0;
  list-style:none;
}

#topmenu li {
display: inline;
}

#topmenu a {
  float:left;
  display:block;
  text-decoration: none;
}


and now the entries for every menu item you want to style:
Code:
#topmenu li.item1 a {
  width: 31px;
  height:28px;
  background: url(../images/home.png) 0 0 no-repeat;
}

#topmenu li.item1 a:hover, #topmenu li#current.item1 a {
  background: url(../images/home-over.png) 0 0 no-repeat;
}

#topmenu li.item64 a {
  width: 27px;
  height:28px;
  background: url(../images/links.png) 0 0 no-repeat;
}

#topmenu li.item64 a:hover, #topmenu li#current.item64 a {
  background: url(../images/links-over.png) 0 0 no-repeat;
}

and so on...


As you can see u will have to use the item numbers to style the items directly.

The result is a nice rollover image menu without any line of javascript or an additional module :)

Feel free to contact me if you like this little hack or have any questions. I'd like to thank the author of the original post again!


Top
  E-mail  
 
Posted: Mon Mar 24, 2008 10:32 am 
User avatar
Joomla! Master
Joomla! Master
Offline

Joined: Thu Aug 18, 2005 10:41 am
Posts: 15089
Moderator note; moving to Tips and Tricks

_________________
Regards Robin


Top
   
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group