Search code examples
imagedrupaldrupal-7content-type

Image type as background in drupal-7


Hi everybody: i had define a new content type that have: a title, a link field, and a image field. So, i want to make that image comes to be the background of the content type when i show it. How can i do that?

Thanks in advance


Solution

  • A very quick way to do this would be to add a custom node.tpl.php to your theme and do this:

    <?php
    $url = file_create_url($node->field_image[$node->language][0]['uri']);
    ?>
    <div style="background:url(<?php echo $url; ?>) left top no-repeat;" id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
    // Rest of node.tpl.php here