Currently using this but I would like to make the link a picture

print( '<a href="/local/node/add/xyz/'. $node->nid.'" >Link Text</a>' );

tried

print( '<a href="/local/node/add/xyz/'. $node->nid.'" ><img src="images/link.gif" border="0"></a>' );

Doesn't seem to work. What have I done wrong?

Cheers

Comments

stevenc’s picture

The src you are using above is not likely a valid path.

Images are usually stored either:
a) in you theme's directory, perhaps in an "images" subfolder. In this case, the src would be: "/sites/all/themes/mytheme/images/link.gif"
b) in the files area, if images are uploaded through the content area. In this care, the src may be: "/sites/default/files/images/link.gif"

Remember, any link defined in the HTML (images, javascript, css files, etc.) is always relative to the path of the current page as seen by the browser itself, not by where Drupal is executing the page.

---------------------------------
Steven Wright

Slalom

JasonMoreland’s picture

great thank you I'll try that out

JasonMoreland’s picture

Is the php correct could the picture not showing up be a css issue?

thorshammer’s picture

When code references a resource (image etc.) from within a node, you have to preface the src= with "../".

dalegrebey’s picture

Use Drupal's l() function for links... The links are automatically going to be relative, it's clean and is best practice/the Drupal way.

This works:

<?php echo l('<img src="' . $directory . '/logo.png" />', $node->nid, array(html=>TRUE)); ?>

What this says is l(where the image is located, what the URL link should be, the code is html)

JasonMoreland’s picture

Excellent than you very much.