大家好:我定义了一个新内容类型,它有:一个标题、一个链接字段和一个图像字段。因此,当我显示它时,我想使该图像成为内容类型的背景。我该怎么做呢?
提前感谢
发布于 2012-02-04 02:16:21
一种非常快捷的方法是将自定义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发布于 2012-02-04 23:58:45
我想对克莱夫的回答发表评论,但没有“代表”:(。检查节点类型不是最好吗?
<?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的其余部分
发布于 2014-09-09 19:10:13
如果您使用Field Group模块,请检查Field Group Background Image。
步骤:
div (background image)字段组作为节点的包装器https://stackoverflow.com/questions/9130997
复制相似问题