I'm trying to create a secondary navigation using images--in the footer region. I am not sure what the correct syntax is to use images as links in PHP.

I looked around and found this script using a Drupal API. Not quite sure if it's what I need--and even how to use it.

function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) {
    $attributes = drupal_attributes($attributes);
    $url = (url($path) == $path) ? $path : (base_path() . $path);
    return '<img src="'. check_url($url) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. (isset($image_attributes) ? $image_attributes : '') . $attributes .' />';
  }
}

I also tried this...(but did not work) leaving PHP to enter HTML then re-entering PHP...

print( '<a href="test.php/"><img src="images/test.png"/></a>' );

And I tried this...did not work. Not sure how to include the URL path using this code.

$imagepath="images/test.jpg";
$image=imagecreatefromjpeg($imagepath);
header('Content-Type: image/jpeg');
imagejpeg($image);

I downloaded a couple of modules--such as the image & imagelinkfield. It doesn't seem like that's what I need also.

If anyone can offer some help, I would really appreciate it.

Comments

Jeff Burnz’s picture

I'd suggest that the best way of using images in menus is with CSS, its light weight, doesn't require any special PHP, preserves accessibility and is easy to do. I outlined the basic idea in this tutorial - you can adapt this to use with any menu.

neu7o’s picture

thanks for the tutorial. i've made CSS + image menus before--but i think implementing it with PHP is what's confusing me.

so here's what i've attempted to do:

style.css file

#secondary{margin: 0px; padding: 0px; width: 700px; height: 125px; float: left;}
#secondary a:links{background-image: url(images/file.png); background-repeat: no-repeat;}
not seeing an image : /

page-front.tpl.php

code in the footer div

if (!empty($secondary_links)):

print theme('links', $secondary_links, array('class' => 'links secondary-links'));

endif;

my goal is to have 3 different images--for my 3 separate links in the footer. not totally sure how to do that--but trying to test to see if one works by using CSS.

not using the secondary links block--it's disabled, but using the $secondary_links variable.

mndonx’s picture

Do you have a different class for each link, based on what the link is? Maybe you can copy the HTML you have to work with for the secondary menu and paste it here.

mndonx’s picture

Are you using blocks? It's best practice not to use PHP in blocks unless you absolutely need to. But if you must, make sure that your Input Format is set to allow PHP code. Otherwise it will get stripped out.

PS - One thing that PHP would be useful for here is stating your path, so you can keep your images in the theme folder: <?php print '<img src="' .base_path() .path_to_theme() .'/images/test.jpg" alt="test" />'; ?>.

neu7o’s picture

not using the secondary links block--it's disabled, but using the $secondary_links variable.

neu7o’s picture

still unsure how to implement CSS with PHP to have image links.

i was looking through the forums and saw this code