图像类型作为drupal-7中的背景

时间:2012-02-03 15:19:57

标签: image drupal drupal-7 content-type

大家好:我定义了一个新的内容类型: 标题,链接字段和图像字段。 所以,当我展示它时,我想让该图像成为内容类型的背景。我怎么能这样做?

提前致谢

3 个答案:

答案 0 :(得分:3)

执行此操作的一种非常快捷的方法是在主题中添加自定义node.tpl.php并执行此操作:

<?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

答案 1 :(得分:3)

我想对Clive的答案发表评论,但没有&#34; rep&#34; :(。对于节点类型的检查,它不是最好的吗?

<?php
if ($type == 'MACHINE_NAME_FOR_YOUR_TYPE') {
    $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; ?>>
<?php } ?>

//其余的node.tpl.php

答案 2 :(得分:0)

如果您使用Field Group模块,请检查Field Group Background Image

步骤:

  1. 转到内容类型的管理显示页面
  2. 创建div (background image)字段组作为节点的包装
  3. 选择要使用的图像字段。 (可选)您可以指定图像样式
  4. 不输出图像字段