WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Templates, Menus & Design => Topic started by: Ogierini on May 09, 2010, 11:26:48 AM

Title: template or background switcher
Post by: Ogierini on May 09, 2010, 11:26:48 AM
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: [Select]
<?php
    
if (( PAGE_ID == ) 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 }
Thanks!
Title: Re: template or background switcher
Post by: aldus on May 09, 2010, 12:30:22 PM
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: [Select]
<?php
    
if (( PAGE_ID == ) 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 ?>
     
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: [Select]
<?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>


Kind regards
Aldus



**) You can leave the argument if you have specify in the head that you always use "text/css" e.g.
Code: [Select]
<meta http-equiv="Content-Style-Type" content="text/css">
Title: Re: template or background switcher
Post by: Ogierini on May 09, 2010, 01:04:23 PM
Thank you Aldus (Dutch?)
I put this code now in the head but it doesn't work yet.
Can your see why?


Code: [Select]
<?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>


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;
Title: Re: template or background switcher
Post by: aldus on May 09, 2010, 01:18:51 PM
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: [Select]
<?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>


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

Kind regards
Aldus
Title: Re: template or background switcher
Post by: Ogierini on May 09, 2010, 01:23:15 PM
Thank you! Gonna try!

Irene
Title: Re: template or background switcher
Post by: Ogierini on May 09, 2010, 01:44:25 PM
ships doesn't work.....

 :?
Title: Re: template or background switcher
Post by: Ogierini on May 09, 2010, 05:35:44 PM
Should this really work, because it doesn't for me?

Is there any other script available, to change css per page?
Title: Re: template or background switcher
Post by: mr-fan on May 10, 2010, 08:46:39 AM
hi,

Code: [Select]
<?php
$filename 
PAGE_TITLE;
$default = &#39;basic.css&#39;

if (file_exists($filename)) {
    
$file $filename;
} else {
    
$file $default;
}
?>

// CSS Ausgabe
<link href="<?php echo TEMPLATE_DIR?>/<?php echo $file?>.css" rel="stylesheet" type="text/css" media="screen" />

=> untested + could work with PAGE_ID, too

regards
martin