WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Templates, Menus & Design => Topic started by: pszilard on August 02, 2008, 02:31:23 PM

Title: Andreas01 - how to change banners per page?
Post by: pszilard on August 02, 2008, 02:31:23 PM
Hi, - I am using template: ANDREAS01

I would like to have different banners for each page. I thought if there was a way to define a default image (e.g banner.jpg) then if there existed a picture with the same name as the page, then it would be inserted, and if not found then it would default to the banner.jpg.

I.e. if the page was called HOME, then if HOME.jpg existed, then that would be used for the banner for the HOME page, but if there was no HOME.jpg, then it would use banner.jpg.

Second question is how to add the page title (h1 tagged) to appear on top of the banner?

Thanx in advance,
Title: Re: Andreas01 - how to change banners per page?
Post by: Bramus on August 02, 2008, 03:09:43 PM
You can do it by an if/else statement in the index.php of the template, for example.
Code: [Select]
<?php
if (PAGE_ID == 1){ ?>

<img src="http://www.bramus.nl/media/wereld-internet.png" alt="Hosting" />
<?php

if (
PAGE_ID == 2) { ?>

<img src="http://www.bramus.nl/media/image2.png" alt="Image2" />
<?php 
}
?>


If you use this you let PHP check what page id the page is they people are visiting, and then it takes the image correspondending to the page id.
Title: Re: Andreas01 - how to change banners per page?
Post by: pszilard on August 02, 2008, 03:27:01 PM
As a PHP dummy, using just code duplication, I got partway by using the following line:

Code: [Select]
<img id="frontphoto" src="<?php echo TEMPLATE_DIR?>/img/<?php echo PAGE_TITLE?>.jpg" width="760" height="175" alt="logo" />
where the original was before,

Code: [Select]
<img id="frontphoto" src="<?php echo TEMPLATE_DIR?>/img/front.jpg" width="760" height="175" alt="logo" />
Using PAGE_TITLE is a lot easier than PAGE_ID, however I need help on the syntax which should say
Code: [Select]
Pseudo code
IF PAGE_TITLE.jpg exist then PAGE_TITLE.jpg else default_banner.jpg

if you get the idea. How would then be coded in PHP?
Title: Re: Andreas01 - how to change banners per page?
Post by: aldus on August 02, 2008, 03:52:22 PM
As for a quick one: a typical job for "switch - case". e.g.
Code: [Select]
<?php
/**
*    @version     0.1.0
*    @date        2008-08-02
*    @package    WebsiteBaker - Code Examples
*
*/

    
switch (PAGE_TITLE) {
        case 
"Home"
            
$image_name "heaven.jpg"
            
$alt_str "this is the heaven";
            break;
            
        case 
"Photos":
            
$image_name "clouds.jpg";    
            
$alt_str "A rainy day in Georgia.";
            break;
            
        case 
"Math c1":
        case 
"Math c2":
        case 
"Math c3":
            
$image_name "math/fractals.jpg"
            
$alt_str "Math: fractals. A Reethmann/Loopfield area in details.";
            break;
            
        default:
            
$image_name "asterix.gif";
            
$alt_str "we don&#39;t need every time the magic-drink.";
    }
    
    
$img_html_str "img src=\"http://www.no_idea.biz/media/\"".$image_name."\" alt=\"".$alt_str."\" />\n";
?>

<!--
    some html in your template here
-->
<? echo $img_html; ?>

Regards
Aldus