2012-01-23 63 views
0

Normaly在Drupal 7,我們有node.tpl.php的Drupal 7:顯示圖像,而不是節點標題

<?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我想加載圖片而不是標題。

我沒有檢查過各種實現,但沒有找到任何解決方案。

[更新]我曾嘗試編輯template.php文件,並添加了用圖像替換標題的函數 - 如果圖像存在。我需要這個在Drupal 7中 - 請看這裏 - http://drupal.org/node/221854

有什麼幫助嗎?謝謝..

回答

0

由於每個節點都有它自己的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> 

但是我相信這不是最好的開發方式,但它適用於你的問題。