Facebook Connect

Connect with Facebook

Nube de Tags

Inicio de sesión

Agregar una imagen ImageCache con PHP

If you want to add manually an image and apply an imagecache preset on it, you need to add a code snippet to the desired .tpl.php file:

<?php

print theme('imagecache', $preset, $image['filepath'], $alt, $title, $attributes); 
?>

Below is an example in which I manually call Imagecache using the namespace small and printing file test.jpg on the root of the Drupal installation directory (the image path should always relative to it). The alt atribute is shown when the image cannot be displayed while the title attribute is meant to be displayed in a tooltip.

<?php

print theme('imagecache', 'small', 'test.jpg', 'just a test image', 'test image'); 
?>

($alt, $title, $attributes are optional, $attributes intentionally omitted in the example, as it's not a very frequently used parameter).

Putting several of these practices together can lead to code such as this:

<?php if ($field_images[0]['view'] > '' ) : ?>
<?php foreach($field_images as $item) { ?>
<div class="images">
<?php print '<img src="/files/imagecache/medium/'.$item['filepath'].'" title="'.$item['title'].'" alt="'.$item['alt'].'">'; ?>
<?php print '<h3 class="img_title">'.$item['title'].'</h3>'; ?>
</div>
<?php } ?>
<?php endif; ?>

Tomado de http://drupal.org/node/163561