Hi All,

Hope this finds you all well! I need to have different background CSS for different pages in Drupal 6. I know how to do this for the front page;

<?php if ($is_front) : print " id=\"front\""; endif;?>

and then I add a body#front for the front page css.....

but let us assume I want to change the CSS for a "About us" Page? How would I do it? I tried to use the same logic but it doesn't appear to work.... so:

<?php if ($is_aboutus) : print " id=\"aboutus\""; endif;?>

Any suggestions or work around would be highly appreciated!

Kind Regards,
DM

Comments

tdimg’s picture

$is_front is the only such variable that Drupal populates. It does, however, populate $node->nid when viewing a node, so try this in your page.tpl.php:

if ($node->nid) : print " id=\"node-" . $node->nid . "\""; endif;

WorldFallz’s picture

You can see the template.php file for the fusion theme (around line 50), for an example of how to setup body classes.

spritemusketeer’s picture

Hi,

I was just looking to do this too. Dariomem I can't get your example to work.

I have tried putting...

if ($is_front) : print " id=\"front\""; endif;

into my page.tpl.php

My first problem is it seems to actually print "id="front"" onto the page.

The second problem is I am not sure how body#front is working in the css.

I have tried the line
body#front #container {background: url("about.jpg")};

But its not working.

Any tips would be greatly appreciated.

Many thanks

Simon

WorldFallz’s picture

I don't understand-- it's printing id="front" because that's exactly what you're telling it to print.

spritemusketeer’s picture

Ah yeah. I am a bit dumb. I guess my problem is more in implementing the body#front within my style sheet. I thought the print id="front" was to store the id state.

Thanks for your reply

Simon

WorldFallz’s picture

ah ok, then what exactly does "not working" mean? Where is the image located? The body#front line looks correct on the surface, but there's really no way to know for sure without more details.

tdimg’s picture

do you actually place this piece of code directly behind body? like:

<body<?php if ($is_front) : print " id=\"front\""; endif; ?>>
spritemusketeer’s picture

Hey thanks for this help.

so in page.tpl.php I have;

 <body
<?php if ($is_front) : print " id=\"front\""; endif; ?>
  		<?php print phptemplate_body_class($left, $right); ?>>  

Then in style.css


body {
  margin: 0;
  padding: 0;
  background: url(images/drupal_interface.png) no-repeat;
  background-position: top left; 
  font: 12px/170% Verdana, sans-serif;
  color: #494949;

}




body#front #container {background: url(images/drupal_interface1.png)};

  

The image drupal_interface1.png is there right next to the other but does not appear on the front page.

Many thanks

Simon

tdimg’s picture

if that is exactly what you have in your style.css, then you should look at the position of the closing brackets and semicolon of your body#front

jpshayes’s picture

Try refreshing your cache

hold down shift and click on your browsers refresh button on a mac

hold down control and press f5 on a pc

spritemusketeer’s picture

It seems to work now.
I think I just messed up my styles.... I did not need #container (I had taken that from another post)

This is the working css.

Thanks Simon


body {
  margin: 0;
  padding: 0;
  background: url(images/drupal_interface.png) no-repeat;
  //background: url(images/drupal_interface.png) fixed center no-repeat;
  background-position: top left; 
  font: 12px/170% Verdana, sans-serif;
  color: #494949;

}

body#front {
	background: url(images/drupal_interface1.png) no-repeat;
}