Hi,
I'm looking for a way to show attached images (via image_attach) in a sidebar block. I haven't found a block snippet which does this andmy PHP skills are not up to the task of writing it myself. I tried to create a block view which does this, but it shows all images that are attached to a node, while I want to show only the attached images from the currently viewed node.
Any suggestions? Thanks!

Comments

Jeroen Coumans’s picture

After digging through the image_attach module, I copied the theme display code and this seems to work:

if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
    if ($node->iid) {
        $img_size = variable_get('image_attach_size_body_'. $node->type, IMAGE_ORIGINAL);
        if ($img_size != IMAGE_ATTACH_HIDDEN) {
            $image = node_load($node->iid);
            if (!node_access('view', $image)) {
                // If the image is restricted, don't show it as an attachment.
                return NULL;
            }
            $output = '<p class="image-attach-body">';
            $output .= l(image_display($image, $img_size), "node/$node->iid", array(), NULL, NULL, FALSE, TRUE);
            $output .= '</p>'."\n";

            print $output;
        }
    }
}

Change the IMAGE_ORIGINAL to 'thumbnail' or 'yoursize' to have it display in a custom size.