WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • template or background switcher
  • Print
Pages: [1]   Go Down

Author Topic: template or background switcher  (Read 5197 times)

Ogierini

  • Guest
template or background switcher
« 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 == 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 }
Thanks!
Logged

aldus

  • Guest
Re: template or background switcher
« Reply #1 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 == 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 } ?>
     
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">
Logged

Ogierini

  • Guest
Re: template or background switcher
« Reply #2 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;
Logged

aldus

  • Guest
Re: template or background switcher
« Reply #3 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
Logged

Ogierini

  • Guest
Re: template or background switcher
« Reply #4 on: May 09, 2010, 01:23:15 PM »
Thank you! Gonna try!

Irene
Logged

Ogierini

  • Guest
Re: template or background switcher
« Reply #5 on: May 09, 2010, 01:44:25 PM »
ships doesn't work.....

 :?
Logged

Ogierini

  • Guest
Re: template or background switcher
« Reply #6 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?
Logged

mr-fan

  • Guest
Re: template or background switcher
« Reply #7 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
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • template or background switcher
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2