1

Normaly in Drupal 7 we have (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); ?>

It is taking node_url and putting it on a Title in every Node.

I do have 5 nodes (pages) displayed:

  • First
  • Second
  • Third etc

I have created images First.gif, Second.gif and I want to load that images instead of Title.

I did check various implementation, but didn't find any resolution for me.

[Update] I did try to edit template.php file and to add functions for replacing title with image-if images exists. I need this in Drupal 7 - please see here - http://drupal.org/node/221854

Is there any help? Thanks

  • It would be helpful if you could let us know what you've tried so no-one gives the same advice. – Chapabu Jan 21 '12 at 13:32
  • Do you only want to replace them on the node page or in everything else as well? – 7wonders Jan 21 '12 at 13:59
  • only on the node page...I have 5 of them. – Adnana Hayo Jan 21 '12 at 14:23
0

Judging from your comment you actually want to change the title that gets output in page.tpl.php (and possibly other page templates). One way to achieve that is adding the following code into your template.php file:

function mytheme_process_page(&$variables) {
  if (isset($variables['node'])) {
    if ($variables['node']->nid == 1) $image = 'First.gif';
    elseif ($variables['node']->nid == 2) $image = 'Second.gif';
    elseif ($variables['node']->nid == 3) $image = 'Third.gif';
    elseif ($variables['node']->nid == 4) $image = 'Fourth.gif';
    elseif ($variables['node']->nid == 5) $image = 'Fifth.gif';
    if (isset($image)) {
      $url = url(path_to_theme() .'/images/'. $image);
      $variables['title'] = '<img src="'.$url.'" alt="'.$variables['title'].'" />';
    }
  }
}

You should switch out 'mytheme' with your actual theme name and change nid values, the path to images (if needed) to get yourself a working solution.

  • If I'm right...this fix will replace only one link Title and put a picture there. I need this for five different pages. ?q=First, ?q=Second,?q=Third. You can see here what I want in Drupal 7 - drupal.org/node/221854 – Adnana Hayo Jan 21 '12 at 15:39
  • I updated my answer, check if it's more helpful now. – Madis Jan 21 '12 at 16:49
  • Unfortunately, the main Title is still Word, not a picture. However, picture loads lower then main Title position but not on the place where main Title is. – Adnana Hayo Jan 23 '12 at 17:01
  • Sounds like you want the title that gets output in page.tpl.php (and possibly other page templates) changed instead then. You can remove the old modifications and check my updated answer for a new solution. – Madis Jan 23 '12 at 21:39
  • This resolution still doesn't work. I have changed 'mytheme' with my actual theme name. Nid values are correct and images path also. Not sure why this doesn't work :((( – Adnana Hayo Jan 24 '12 at 17:11
2

For non-coders: the views slideshow module (or something similar) could easily solve this problem without requiring custom code to maintain.

From http://drupal.org/project/views_slideshow:

Views Slideshow can be used to create a slideshow of any content (not just images) that can appear in a View. Powered by jQuery, it is heavily customizable: you may choose slideshow settings for each View you create.

Potential uses News item slideshow (such as the title, image and teaser of the last 5 news articles submitted) The Last X number of X submitted (images, videos, blog entries, forum posts, comments, testimonials, etc.). Rotate any image, based on any filters you can apply in views. Hottest new products for any ecommerce drupal site. Rotate contact links, share links, etc. Heck, you could rotate entire nodes, categories, image galleries, etc. I wouldn't suggest it, but you have that power. Its also a great space saver. Places where you had multiple images or multiple items such as RSS feeds or category listings can now be presented in a slideshow. The possibilities are really endless, as the more ways you can think of to categorize and add to views, the more you can rotate.

1

I believe that a simpler answer would be to manage your node fields better. If you created a new image field for each node, and only insert images for those nodes that need them then you could modify your template.php like in the example above and only replace the output for each one as needed, versus what amounts to a Drupal hack instead. When your output is generating data separate from the data I feel like this makes the whole thing harder to update. I mean, what if you upgrade your theme? You could lose all of those edits.

Just a thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.