Different header background images for each page -> how? [SOLVED]

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
rj
Forum Members
Forum Members
Posts: 70
Joined: Fri Aug 10, 2007 4:58 am

Different header background images for each page -> how? [SOLVED]

Post by rj »

I'm currently making a website where I want each page (5 to be exact) to have a different header background images. I know it can be done with 5 different templates where I give each #header a different id. Linking them to another 5 different stylesheets where I specify de background-image for the #header would do the job.
But that's what I'm trying to avoid. I'm looking for a way to use just one template and one stylesheet because in the future more pages will be added to the site. I was wondering if this could be done with some sort of dynamic code. But maybe there's another "trick" to accomplish this.

Anybody with ideas / a solution to this matter?

TIA. Your help is greatly appriciated.
Last edited by rj on Wed Aug 15, 2007 5:31 pm, edited 1 time in total.
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: Different header background images for each page -> how?

Post by RonnyK »

rj
Forum Members
Forum Members
Posts: 70
Joined: Fri Aug 10, 2007 4:58 am

Re: Different header background images for each page -> how?

Post by rj »

Hi Ronny,

thanks for the link. Do you have any experience with this plug-in? More importent...does it work under version 1.1?

Richard
faglork

Re: Different header background images for each page -> how? [SOLVED]

Post by faglork »

Hi,

I suggest writing an UDT which works like this:

- get the name of the page
- construct an image path according to the pagename
- check if image exists, if not, use default
- output the image URL

Then all you have to do is to
- create a directory "/uploads/images/backgrounds"
- upload  images with the pagename as filename. If you don't, it will use a default pic.

Here's the code (just a quick hack you have to test it):

User defined tag "autobg"

Caution: substitute *your* server path in the $filename variable.

Code: Select all

global $gCms;
$picname =& $gCms->variables['page_name'];

$filename = '/www/123/html/uploads/images/backgrounds/'.$picname.'.jpg';

if (file_exists($filename)) {
    echo "/uploads/images/backgrounds/$picname.jpg";
} else {
    echo "/uploads/images/backgrounds/default.jpg";
}
In your template, just hardcode the background image for the H1 in the header div  like this:
{autopic}

Code: Select all

   <div id="header">
           <h1 style="background-image: url({autobg});"><a href="/">Your page title here</a></h1>
   <hr class="accessibility" />
   </div>
As I said, it is a quick hack and may not work from the spot but you get the idea.

HTH,
Alex
Post Reply

Return to “Layout and Design (CSS & HTML)”