Changing background with every page.

Permalink
Hello. I'm fairly new to Concrete5. I have been developing a website for a client in which they would like the background image to change with each page. With the theme I'm developing, I can get this to happen using this code for the change. This is the code for bgchange.php, which echos out css into style tags in my default.php.
#container{
<?php
$urlSTR = "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
if ($urlSTR == "http://localhost/concrete/")
{ 
echo "background-image:url(\"images/backgrounds/people.png\");   background-color: #008800;" ;}
else{echo "background-color: #880000;" ;}
?>
}


and here is where it goes

<style type="text/css">
<?php include 'bgChange/bgchange.php';?>
</style>


it looks like it is working, except that no image is displayed.
The color is green if the url's match and red if not.

I could use an explanation or some help as to what I need to do to get the Background to change.
Any help is appreciated.

Thanks!

adane1
 
TheRealSean replied on at Permalink Best Answer Reply
TheRealSean
You mean like this,
http://www.dokimos.org/ajff/


Joking aside, I would add in a different class dependant on either the page name or page class.

Then move the background image into the css,

an example would be

//this uses the page url for a class, but you could assign an attribute if you wanted the same bg on different pages
//you would do the following in the header, you could do this on any div not just the body tag
$c=Page::getCurrentPage();
<body class='$c->getCollectionHandle()'>



Then in your css, you could refer to your body images, using

body{ background-color:#333;}
body.home { background-image:url(images/image1.jpg)}

You example seems to suggest you are using php css which I dont believe will parse so wont add the needed paths to your image directory. So you would need to use relative paths to your images from the root,

/themes/your_theme/images/backgrounds/people.png
adane1 replied on at Permalink Reply
adane1
Thank you so much!

I found where my issue was from the last line you posted.

I was in fact losing the image because I wasn't linking it properly.
What I ended up doing was adding "themes/myTheme/" before the "images/backgrounds/people.png" and TAH-DAH!

I'm going to have to read up more on the way concrete uses the classes before I try the other method you mentioned.

Thanks again!
alancurrall replied on at Permalink Reply
alancurrall
Hi I've just tried and tried to do as you say above, but BG not showing up any help would be appreciated. See extract code from:
main.css
body {/* customize_background */ background-color: #000000; /* customize_background */ padding: 0px; margin: 0px; }

body.home { background-image:"images/main-bg.png"}

header.php
<body>

$c=Page::getCurrentPage();
<body class='$c->getCollectionHandle()'>

<div id="page">

Thanks,
Alan
TheRealSean replied on at Permalink Reply
TheRealSean
try background-image: url(images/main-bg.png);

your code snippet is missing the "url()"