WebsiteBaker Support (2.8.x) > Templates, Menus & Design

template or background switcher

(1/2) > >>

Ogierini:
hello guys,

I would like to have a different background on every page of a website.
I tried this code in the head but it doesn't work.
Has anyone a good suggestion?



--- Code: ---<?php
    if (( PAGE_ID == 2 ) OR (PAGE_ID == 22)){
     ?> <style type="styleskoen.css">
     #intro_right{
     background: #179FB7 url(<?php echo WB_URL.&#39;styleskoen.css&#39;;?>) no-repeat;
     }
     </style><?php }

--- End code ---
Thanks!

aldus:
Hello Irene

There are a couple of reasons that the code doesn't work at all, as
1) the style-tag attribute "type" has to be to set "text/css" **) and 2) the url
for the background-image has to point to a valid image[-format] (e.g. gif, jpg, png ...);
__not__ to a css-file at all:

--- Code: ---<?php
    if (( PAGE_ID == 2 ) OR (PAGE_ID == 22)){
     ?> <style type="text/css">
     #intro_right{
     background: #179FB7 url(<?php echo WB_URL.&#39;styleskoen.jpg&#39;;?>) no-repeat;
     }
     </style><?php } ?>

--- End code ---
     
And 3) ist the image realy placed inside the WB-Root, instead of e.g. the media-folder?

Also, to avoid unreadable mess of "if - elseif - else OR - elseif AND - endif - but_no_if"-constructions
for future, if e.g. the site is growing - i would prefert a simple "switch" , e.g.

--- Code: ---<?php
switch( PAGE_ID ) {
case 2:
case 22:
$image_name = &#39;stylekoen.jpg&#39;;
break;

default:
$image_name = "not_found.gif";
}

$imgage_url = WB_URL.MEDIA_DIRECTORY."/".$image_name; // what/where ever ...

?>
<style type="text/css">
#intro_right{
background: #179FB7 url(<?php echo image_url; ?>) no-repeat top left;
}
</style>


--- End code ---

Kind regards
Aldus


**) You can leave the argument if you have specify in the head that you always use "text/css" e.g.

--- Code: ---<meta http-equiv="Content-Style-Type" content="text/css">

--- End code ---

Ogierini:
Thank you Aldus (Dutch?)
I put this code now in the head but it doesn't work yet.
Can your see why?



--- Code: --- <?php
switch( PAGE_ID ) {
case 2:
case 22:
$image_name = &#39;templates/a_bit_modern/Images/bgkoen.gif&#39;;
break;

default:
$image_name = "not_found.gif";
}

$imgage_url = WB_URL.MEDIA_DIRECTORY."/".$image_name; // what/where ever ...

?>
<style type="text/css">
#intro_right{
background: #179FB7 url(<?php echo image_url; ?>) no-repeat top left;
}
</style>
--- End code ---


And then, If I want to switch on page 3, how can I achieve that?

 <?php
   switch( PAGE_ID ) {
      case 2:
      case 22:
         $image_name = 'templates/a_bit_modern/Images/bgkoen.gif';
         break;

aldus:
Hello Irene

Sorry - no Dutch -

YOu will have to modify the url to the images - as i didn't knew where they are in my example.

So:

--- Code: ---<?php
switch( PAGE_ID ) {
case 2:
case 22:
$image_name = &#39;bgkoen.gif&#39;; // *!
break;

case 3:
$image_name = "no_idea_about_the_name.gif"; // *!
break;

default:
$image_name = "not_found.gif";
}

$imgage_url = WB_URL."/templates/a_bit_modern/Images/".$image_name; // *!

?>
<style type="text/css">
#intro_right{
background: #179FB7 url(<?php echo image_url; ?>) no-repeat top left;
}
</style>


--- End code ---

please take a (deeper) look for the lines marked with *!
Maybe this makes something clearer ;-)

Kind regards
Aldus

Ogierini:
Thank you! Gonna try!

Irene

Navigation

[0] Message Index

[#] Next page

Go to full version