Hello,
Does anyone know if there is a way to dynamically change an image (header in this case) that is loaded as a background in a css file to a different image for each page using the same header.html include file?
Thanks
Hello,
Does anyone know if there is a way to dynamically change an image (header in this case) that is loaded as a background in a css file to a different image for each page using the same header.html include file?
Thanks
You would rename your stylesheet from .css to .php. Then you would put the following line in the first line:
header("Content-type: text/css");
Then, for the id, you could do something like this:
$thisPage = $_SERVER['REQUEST_URI'];
switch($thisPage)
{
case "/index.php":
$header = 'header1.jpg';
break;
case "/aboutus.php":
$header = 'header2.jpg';
break;
case "/services.php":
$header = 'header3.jpg';
break;
}
echo "#header{ background-image: url($header);";
Thanks for that, however, I couldn’t get it to work.
I’ve set up the files on a test server http://polymaze.funformentals.com/ with a zip file here in case you are willing to look at it.
Not sure I understand your question, but I’ll try. It seems you want to change the header image for each page.
Assume you have 1-10 images in a folder called Photos. Then you’d do something like:
<?php
$num = mt_rand ( 1 , 10 );
?>
<style>
body {
background: .../photos/<?= $num; ?>.jpg;
}
</style>
Something like that. Again, I don’t quite understand what you want to do, so this is the best I can help.
o, sorry.
What I’m trying to do is set the header image for each page, (home, about, etc…) by designating the header background image through the css. However, each page has a different background image, and I thought it would be possible to have the #header background image in the css file targeted in the first line of each page. Like:
<?php # index.php
$page_title = ‘home’;
($page_headerimage - tells which image to load)
require_once (’./includes/header.html’);
?>
Does that make sense? I’m really new to php and not sure if I’m explaining this correctly.
:: Copyright KIRUPA 2024 //--