WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Templates, Menus & Design => Topic started by: batcity on August 20, 2008, 04:23:18 AM

Title: Edit Index.php [Template] Help
Post by: batcity on August 20, 2008, 04:23:18 AM
I'm trying to include an imagevar.php script which will display a table containing three random images in the header area of a site.  I'm using the vincent03 template.  The imagevar1.php resides in the root folder.  I tried this:

<!-- mainContainer holds the thin line and everything in it-->
<div id="mainContainer">
    <!-- everything within the white bordered area -->
    <div id="container">
        <!-- masthead holds the header and page title in semi transparent bar -->
        <div id="masthead">

        <center>
            <table border="0" cellpadding="0" cellspacing="0" width="95%">
              <br><br>
              <tr>
                <td width="33%" align="center"><?
                include '../../imagevar1.php';
                ?></td>
                <td width="33%" align="center"><?
                include '../../imagevar1.php';
                ?></td>
                <td width="34%" align="center"><?
                include '../../imagevar1.php';
                ?></td>
              </tr>
              </table>
        </center>
       

        <div class="stripe"><h1><?php echo PAGE_TITLE; ?></h1></div>
        </div>

I'm not sure about the syntax here, but it does work on a Non-WB site.  I'm also not sure about the relative addressing because of the wb structure.  Any suggestions appreciated.

The site is www.allredhairsalon .com.  I pulled the code out since it isn't working.  I'd like the images to show up under the address/phone number lines.
   
Title: Re: Edit Index.php [Template] Help
Post by: johnp on August 20, 2008, 04:48:03 AM
I not quite sure if this would help, but it seems that you had the same issue back on November 16, 2007

Here is the link to it
https://forum.WebsiteBaker.org/index.php/topic,7853.0.html (https://forum.WebsiteBaker.org/index.php/topic,7853.0.html)

Not many post! But it appeared that a resolution was found
Quote
I figured out the solution.  Had to use the Sections feature and add the code section above the WYSIWYG section.  Had to add other sections to format the includes.  Pretty clugy, but it worked.  Thanks for help.

Hope this points you in the right direction..

If not try changing
Code: [Select]
<?
            include '../../imagevar1.php';
              ?>

to
Code: [Select]
<?php include("../../imagevar1.php"); ?>

John
Title: Re: Edit Index.php [Template] Help
Post by: BerndJM on August 20, 2008, 04:55:46 AM
Hi,

1.  the "short" opening tag for php: <? din't work on different configurations the safer way ist to use the "normal" tag: <?php

2. the include needs brackets:
Code: [Select]
<?php include (&#39;../../imagevar1.php&#39;); ?>

3. if you're in trouble with the relative adressing you can try this:
Code: [Select]
<?php include (WB_PATH.&#39;/imagevar1.php&#39;); ?>

Regards Bernd
Title: Re: Edit Index.php [Template] Help
Post by: batcity on August 20, 2008, 05:21:00 AM
Got it.  It was a combination of addressing and syntax.  Turns out I can address directly in both the index.php file and in the var script.  Thanks a bunch for your help!  Appreciate it!

The imagevar1.php script looks like this:

<?php

$imagevar=rand(1, 3);
if($imagevar==1)
  {
    print "<img src='images/header/img_01.jpg'>";
  }
else if($imagevar==2)
  {
   print "<img src='images/header/img_02.jpg'>";
  }
else if($imagevar==3)
  {
   print "<img src='images/header/img_03.jpg'>";
  }

?>

and the modified header code looks like this now (and it works).  Just have to get the correct images and play with the spacing.

<div id="masthead">

        <center>
            <table border="0" cellpadding="0" cellspacing="0" width="75%">
           
              <tr>
                <td width="33%" align="center">
                <?php include ('imagevar1.php'); ?>
                </td>
                <td width="34%" align="center">
                <?php include ('imagevar1.php'); ?>
                </td>
                <td width="33%" align="center">
                <?php include ('imagevar1.php'); ?>
                </td>
              </tr>
              </table>
        </center>


        <div class="stripe"><h1><?php echo PAGE_TITLE; ?></h1></div>
        </div>
Title: Re: Edit Index.php [Template] Help
Post by: batcity on August 20, 2008, 05:57:10 AM
Note:  I also had to move a copy of the imagevar.php files and the images/ folder to the /pages directory. 
Title: Re: Edit Index.php [Template] Help
Post by: aldus on August 20, 2008, 10:07:58 AM
Hello

Instead of a mess of "if-then elseif" combinations i would prefer to make it direct, e.g.

Code: [Select]
<?php
/**
*    @version    0.2.0
*    @date        2008-08-20
*    @author
*    @package    WebsiteBaker - Code examples
*    @state        @dev
*
*    Getting a random image for the header;
*    in the form "img_0<1|2|3>.jpg"
*
*/

echo "<img src=&#39;images/header/img_0".rand(1,3).".jpg&#39;>";

?>


And instead of calling an external file inside the template three times
you can keep it small and simple like this one:
Code: [Select]
<center>
    <table border="0" cellpadding="0" cellspacing="0" width="75%">     
        <tr>
            <td width="33%" align="center"><? echo "<img src='images/header/img_0".rand(1,3).".jpg'>"; ?></td>
            <td width="34%" align="center"><? echo "<img src='images/header/img_0".rand(1,3).".jpg'>"; ?></td>
            <td width="33%" align="center"><? echo "<img src='images/header/img_0".rand(1,3).".jpg'>"; ?></td>
        </tr>
    </table>
</center>

Regards
Aldus