Problem with template?

Hi,

I am trying to code my website so that it will use a template for every page. I used a web-builder tool originally to make the site, but ran into problems with it because it encrypted my index page so that I could not edit the code. So I am trying to rebuild everything so that I can freely edit the codes of my various pages.

I am having a hard time making it so that the content of the page shows where I want it to…

My Website: www.wubbiepets.com/atest/index2.php

So you can see where I want the content to show… however, down at the bottom where it says “Content?” is where the content is actually showing up. Here is the code to the template I am using:

<?php include('variables/variables.php'); ?> /* Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License */ body { background-image:url("/images/backgroundimg1.png"); text-align: justify; font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-size: small; text-align: justify; color: #555E4F; } h1, h2, h3, h4, h5 { margin: 0; } /* Header */ #header { width: 700px; margin: 0 auto; color: #808080; } #header h1 { float: left; margin: 0px 0 0 0px; font-size: 50px; letter-spacing: -7px; } #header h2 { float: right; margin: 40px 20px 0 0; font-size: 18px; letter-spacing: -2px; } a { color: #666666; text-decoration: none; } a:hover { color: #555E4F; text-decoration: none; } /* Menu */ #menu1 { float: left; width: 160px; margin: 0px auto; padding-bottom: 20px; text-transform: uppercase; font-weight: bold; font-size: 14px; color: #323B2E; } #menu1 ul { margin: 0px; list-style: none; padding: 0px; } #menu1 li { } #menu1 a { display: block; width: 190px; padding: 15px 0px; background-color: #D9D9D9; border-top: 1px solid #EDEDED; border-bottom: 1px solid #B5B5B5; text-align: center; text-decoration: none; text-transform: uppercase; font-weight: bold; color: #808080 ; } #menu1 a:hover { background-color: #8A8A8A; border-top: 1px solid #E3E3E3; border-bottom: 1px solid #E3E3E3; color: #FFFFFF; } /* Content */ #content { width: 700px; margin: 0 auto; padding-top: 10px; border: 10px solid #FFFFFF; border-top: none; background: #E9EAE2; } #colOne { float: left; width: 190px; margin-top: 20px; padding: 0 10px 0 20px; } #colTwo { float: right; margin-top: 20px; width: 440px; padding: 0 20px 0 20px; } #content h2 { margin-bottom: 20px; font-size: 18px; letter-spacing: -1px; color: #808080; } #footer { width: 700px; margin: 0 auto; padding-top: 20px; } #footer p { text-align: center; padding: 0; font-size: 10px; }

<?php echo $website ?>

<?php echo $slogan ?>

 

News

<?php echo $news ?>

WubbiePets

(This is where content should go... but does not?)

 

<?php echo $footer ?>

This was a html template originally. To make it more versatile, I turned it into a .php file and added some php codes… but I cannot figure out how to make it display my page content where it says “(This is where content should go… but does not?)”.

I am VERY new at using php… but is there a code I can use to make my content appear in the right place? Can anyone help me with this?

Thank you in advance,
Wubbie

if your content is stored in a variable then put that instead of

<p>(This is where content should go... but does not?)</p>

[php]

<?php echo $content;?>

[/php]

Thank you for your reply.

The content that I want to display is written on the “index2.php”. I would like to use this same template for all of my different pages - so that if I have to change the layout, I can just edit the template and have it apply to every page of my website. Is there a way to make it so that the template would display different content according to each page, but have pretty much the same code in the template that will work for every page?

Ok I get what your after the best way is to create your template file as you have above then in any file you want to use that template put your content in then load the template like this:

[php]

<?php //include config for database settings require_once ('config.php'); //set page title $title = 'About Us'; ob_start(); //place any html below ?> <?php //store page content into $content to be used in the template $content = ob_get_clean(); //load template require_once ('templates/layout.php'); ?>

[/php]

Thank you, I think that’ll work.
How do I set up a config.php though? ^^;

create a file called config.php and place your database settings and anything thing else you would need to use site wide, I like to have a var with the site path for example like this:

[php]

<?php define('DB_SERVER', 'localhost'); define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_NAME', 'dnname'); define('DIR', 'http://localhost:8080/site/'); define('SITEEMAIL', '[email protected]'); define('SITETITLE', 'Site Name Here'); date_default_timezone_set('Europe/London'); $currentTime = date('G:i:s'); $currentDate = date('Y-m-d'); $dateandtime = date('Y-m-d G:i:s'); @$conn = mysql_connect (DB_SERVER, DB_USER, DB_PASSWORD); @mysql_select_db (DB_NAME,$conn); if(!$conn){ die( "Sorry! There seems to be a problem connecting to our database. Please give us a few minutes to remedy the problem. Thank you."); } session_start(); ob_start(); error_reporting(E_ALL ^ E_NOTICE); ?>

[/php]

Thank you so much =D

I seem to be getting an error now:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/wubbiep1/public_html/atest/index2.php:14) in /home/wubbiep1/public_html/atest/config.php on line 19

What does that mean?

it means something has already been printed on the browser before the session started there should be nothing printed before the session starts

Sponsor our Newsletter | Privacy Policy | Terms of Service