Drupal 6
I am using <?php print $node->content['image_attach']['#value'] ?>
in the node.tpl.php
template file to retrieve the image and getting the image linking to its node.
How can I get the image path only?
EDIT: There is no related CCK field. It is image attach module. Please see https://i.sstatic.net/1jYji.jpg
If I understand correctly from your comments, you attach an image to a node via the Image Attach submodule of Drupal 6's Image module.
The way this submodule works is when you attach an image to your node, it creates a new node for that image first and attaches that new node to your original node. In a way similar as how "modern" entity references work in Drupal 7 and 8.
You can confirm that attaching an image creates a new node by going to your admin/content/node
overview and see a new node of type image
appear in the listing.
The simplest way of retrieving the information of that node is by fetching it from the information on the current node
object:
$paths = $node->image_attach[0]->images
This will retrieve a set of file paths to the various versions of the image. For example:
$original_path = $node->image_attach[0]->images['_original']
Will link to your original, unaltered image, whereas:
$thumbnail_path = $node->image_attach[0]->images['thumbnail']
Will link to its thumbnail version (if present).
As you might know, the Image Attach submodule allows for you to add multiple images to your node. In my example I have blindly taken the first image present by using [0]
. If you have multiple images you should, of course, loop over the various entries present on your image_attach
array.
If you wish to retrieve even more information about each image node that got attached to your original node, you could also load the actual node itself and work with that:
$nid = $node->image_attach[0]->nid;
$image_node = node_load($nid);
Here you fully load the referenced node and have all of its info available.
The latter case, however, would cause unnecessary overhead for there is no extra information present when fully loading the node. The full reference is already provided by the Image Attach submodule inside of your original node
object. Just know Image Attach actually creates extra image nodes underwater which you can treat as such.