I'm trying to theme image nodes using the Aberdeen theme. Currently the node image is output after the node body text - I'd like to make the image appear first, or alongside the body text. How can I do this?

Comments

nwe_44’s picture

you need to duplicate the node.tpl.php and rename it node-image.tpl.php. this new file is where you can theme the appearance of your image nodes. The code you want in there will look something like

  <?php if ($picture) print $picture; ?>  
    
  <div class="content">
    <?php print $content; ?>
  </div>

underpressure’s picture

How would you add a custom style sheet to the node.image.tpl.php???

tvaughan’s picture

Many thanks for the reply - after a LOT of Googling I managed to get to this in my node-image.tpl.php:

print $node->content['image']['#value'];
print $node->content['body']['#value'];

My next problem is how to make the displayed image a different size (i.e. display the thumbnail in the node body)

nwe_44’s picture

perhaps it would be easier to use the image modules own api rather than burrowing through the array yourself as that will give you better future proofing.

try

image_display($image, 'thumbnail');

or if you want it to be a link you could use something like

l(image_display($image, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE);

to add a custom stylesheet to the template add something like

<?php
drupal_add_css(path_to_theme() .'/css/custom_stylesheet.css');
?>

or whatever the route to your file is.

Hope this helps.

nwe_44’s picture

Sorry, my last post had a slight friday style logic to it.

It might have been more easily understandable if I wrote


image_display($node, 'thumbnail');

tvaughan’s picture

Really helpful, thanks!

drewish’s picture

Status: Active » Fixed
sprugman’s picture

Status: Fixed » Active

I need to find the size of my images (in pixels). I'm using the image module, and have created several sizes in the admin. It's happily generating images for me, but I can't figure out how to tell what the actual generated size is.

I've got $node->iid, so I could probably use that to search the db, find the filepath, and use getimagesize. Yuck.

I've also got $node->content[image_attach], so I could search that string for the information. Also yuck.

Presumably, there's some simple function I'm supposed to call, or something, right? Please?

TIA

sprugman’s picture

I need to find the size of my images (in pixels). I'm using the image module, and have created several sizes in the admin. It's happily generating images for me, but I can't figure out how to tell what the actual generated size is.

I've got $node->iid, so I could probably use that to search the db, find the filepath, and use getimagesize. Yuck.

I've also got $node->content[image_attach], so I could search that string for the information. Also yuck.

Presumably, there's some simple function I'm supposed to call, or something, right? Please?

TIA

drewish’s picture

sprugman’s picture

that's just a wrapper for getimagesize. What I'm really looking for, I guess, is how to find $file, given $node->image_attach_iid

sprugman’s picture

I figured it out. I thought there would be a method for this, but:

$im = node_load(array('type' => 'image', 'nid' => $n));

from there you can get the file for the desired size, and from there use image_get_info

Anonymous’s picture

Status: Fixed » Closed (fixed)
intu.cz’s picture

And what did you put into the template.php? Thanks for any info.

lazbay’s picture

Version: 5.x-1.x-dev » 7.x-1.x-dev
Component: image.module » documentation