Drupal Image Button Menu

By Unknown | Labels: , , ,

So I needed to use images in a simple navigation for a customer using Drupal 6.0. Custom theming in drupal is something I have not done a great deal of and my last experience with it was back in drupal 5. So here I am going to document the method I used to change the primary link stack over to images.

/themes/nameoftheme/images/page_title.png

is the method I am storing the image files in. I open up template.php and add the following code to it:


<?php
function imagemenu($linkset){
 foreach($linkset as $link){
  /*
  set image path to theme directory/images/page_title.png
  */
  $imgpath = base_path() . path_to_theme() . "/images/" . strtolower(str_replace(" ", "_", $link["title"])) . ".png";
  $hrefpath = base_path() . $link["href"];
  if (file_exists($_SERVER{'DOCUMENT_ROOT'} . $imgpath)){
   $imageout .= "" . $link["title"] . "";
  };
 };
 return $imageout;
};
?>


Then in the page.tpl.php file where the primary link navigation was going to appear I used the following code:


<?php if (isset($primary_links)) { ?><?php print imagemenu($primary_links)?><?php } ?>


it is crude but it working for the time being and has the added benefit of hiding pages that I do not currently have images for.

0 comments:

Post a Comment