Drupal 7:显示图像而不是节点标题


Drupal 7: Display images instead of nodes titles

在Drupal 7中,我们通常有node.tpl.php:

<?php print render($title_prefix); ?>
    <?php if (!$page): ?>
        <h2<?php print $title_attributes; ?>>
            <a href="<?php print $node_url; ?>"><?php print $title; ?></a>
        </h2>
    <?php endif; ?>
<?php print render($title_suffix); ?>

它取$node_url,并将其放在每个节点的标题上。

我确实显示了5个节点(页面):

  • 第一
  • 第二
  • 第三等

我已经创建了图像First.gifSecond.gif,我想加载这些图像而不是标题。

我确实检查了各种实现,但没有找到任何适合我的解决方案

[Update]我确实尝试过编辑template.php文件,并添加了在存在图像的情况下用图像替换标题的功能。我需要这个在Drupal 7-请看这里-http://drupal.org/node/221854

有什么帮助吗?谢谢

由于每个节点都有自己的id,因此我建议您在特定的files文件夹中包含图像,如node-12node-13等。

在您的node.tpl.php

<?php
// path to our file depending on node id
$file = "path/to/file/node-{$node->nid}.gif";
// check if file exists
if (file_exists($file)) {
    // theme $title as image with theme_image()
    $title = theme('image', array('path' => $file));
}
?>
<h2<?php print $title_attributes; ?>>
    <a href="<?php print $node_url; ?>"><?php print $title; ?></a>
</h2>

然而,我确信这不是最好的开发方式,但它适用于您的问题。