Different Header Images for Different Nodes

VivekDubey - November 11, 2006 - 07:54

Drupal provides same header for the whole site and if we want to theme all the nodes individually then it’s a bit complicated process. While looking for alternatives to this, the following snippet work fine, this has been implemented in www.vinrcorp.com you can see the example before using it. The usage of the snippet is also quit simple just put this code into the header part or where ever you want, of page.tpl.php file of your theme.

<table>
  <tr>
    <td><img src="[path to image folder]/images/<?php
   
if ($node->nid == 1) {
    print
'image-1.jpg" />';
    }elseif (
$node->nid == 2){
    print
'image-2.jpg" />';
    }elseif (
$node->nid == 3){
    print
'image-3.jpg" />';
    }elseif (
$node->nid == 4){
    print
'image-4.jpg" />';
    }elseif (
$node->nid == 5){
    print
'image-5.jpg" />';
    }elseif (
$node->nid == 6){
    print
'image-6.jpg" />';
    }elseif (
$node->nid == 7){
    print
'image-7.jpg" />';
    }elseif (
$node->nid == 8) {
    print
'image-8.jpg" />';
    }elseif ((
$node->nid == 9) | ($node->nid == 10)){
    print
'image-9.jpg" />';
    }elseif (
$node->nid == 11) {
    print
'image-11.jpg" />';
    }else {
    print
'default-image.jpg" />';
    }
?>

</td>
  </tr>
</table>

To use it just put images in the image folder and mention the path in the code and also replace the names of images as per the node ids. This will help you to display different banner images for different nodes.
I think you can use it and this works for you too. You can reply to this post for further help.

Vivek Dubey

How to assign different header image for each taxonomy/category

ica - November 11, 2006 - 15:19

Nice one, I think your post should be placed under Handbookes/PHPTemplate Theme Snippets
http://drupal.org/node/45471

and the next question would be;
How to assign a header image for each taxonomy/category instead of each node as your example above...
any definitive snippet on this?

Take a look at the taxonomy image module

nevets - November 11, 2006 - 15:40

Take a look at the taxonomy image module which allows you to associate an image with a taxonomy term. It provides a function to get the image (as an image tag) associated with a given term (see the README).

Taxonomy Image

guitarmiami - March 28, 2007 - 18:19

Taxonomy Image is able to place a taxonomy-based image in a node, but I haven't figured out how to place the images in page.tpl.php (e.g., a banner).

If anyone knows how to put taxonomy images in page.tpl.php, I'm looking for the answer...

Thanks

hi Vivek. Your snipplet is

mboudey - January 31, 2007 - 21:47

hi Vivek.
Your snipplet is great. It works fine.
I was wondering how could I change the header in pages like contact that doesn´t have an ID. Would you know?
Thanks.
Michaël

Hi Michaël, Your problem

VivekDubey - February 3, 2007 - 16:05

Hi Michaël,
Your problem can be solved by using the following snippet;

}elseif (arg(0) == 'contact') {
print 'your image name goes here" />';

I hope you got the idea that in elseif you are required to check if arg(0) == 'contact'
And if true display image of your choice.
I hope this should work as I have tested it, but in case you face any other problem let me know.
Best of luck.

Vivek Dubey

www.vinrcorp.com
Motivates Core Competence

Hi Vivek, Thanks so

mboudey - February 10, 2007 - 01:30

Hi Vivek,
Thanks so much.
Michaël

 
 

Drupal is a registered trademark of Dries Buytaert.