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.8 is now available!


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 »
  • Edit Index.php [Template] Help
  • Print
Pages: [1]   Go Down

Author Topic: Edit Index.php [Template] Help  (Read 7229 times)

Offline batcity

  • Posts: 30
Edit Index.php [Template] Help
« 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.
   
Logged

johnp

  • Guest
Re: Edit Index.php [Template] Help
« Reply #1 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

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
« Last Edit: August 20, 2008, 04:56:48 AM by johnp »
Logged

Offline BerndJM

  • Posts: 1764
  • Gender: Male
Re: Edit Index.php [Template] Help
« Reply #2 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
Logged
In theory, there is no difference between theory and practice. But, in practice, there is.

Offline batcity

  • Posts: 30
Re: Edit Index.php [Template] Help
« Reply #3 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>
Logged

Offline batcity

  • Posts: 30
Re: Edit Index.php [Template] Help
« Reply #4 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. 
Logged

aldus

  • Guest
Re: Edit Index.php [Template] Help
« Reply #5 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
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • Edit Index.php [Template] Help
 

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