Edit Index.php [Template] Help

aldus

Hello

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


<?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='images/header/img_0".rand(1,3).".jpg'>";

?>



And instead of calling an external file inside the template three times
you can keep it small and simple like this one:

<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

batcity

Note:  I also had to move a copy of the imagevar.php files and the images/ folder to the /pages directory. 

batcity

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>

BerndJM

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:

<?php include ('../../imagevar1.php'); ?>


3. if you're in trouble with the relative adressing you can try this:

<?php include (WB_PATH.'/imagevar1.php'); ?>


Regards Bernd
In theory, there is no difference between theory and practice. But, in practice, there is.

johnp

#2
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

Not many post! But it appeared that a resolution was found
QuoteI 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
<?
            include '../../imagevar1.php';
              ?>


to
<?php include("../../imagevar1.php"); ?>


John

batcity

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.