How to not have all the code in one site page...

Soldato
Joined
31 Oct 2005
Posts
8,845
Location
Leeds
Sorry, another question, and another vague title

Currently I'm creating pages "all in" so to speak, with HTML and PHP etc all stuck in one file

I want to have one index page that just says

include or require_once CSS, Divs, Content, etc

Therefore keeping the code tidy

I'm not asking for help, I just want to know what this method is called so I can go a googling to learn

Many thanks
 
Dunno if there is a name for it but you just need to learn how to separate your header, footer and content and learn how to reference them. Its all simple once you understand how a bit of HTML and PHP.

I tried earlier, I created a php file called index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
include($hello.php)
?>
<body>
</body>
</html>

This was hello.php

<?php
print "<br />This is a test "
?>

all I got were error messages
 
pass hello.php as a string, its not a variable so you dont need the dollar sign. try include('hello.php'). If you know the absolute path to hello.php then use that as its faster than giving a relative path.

legend, gives me something to build on now

God you lot must be laughing at me:D
 
right I've ht another snag, or two

Anyhoo I've now got a basic page that simply displays a line of text from a PHP file

How do I set out for example including a CSS file, or the DIVs for content

As I tried include('css.css') and had an error

What I'm basically asking is , well maybe could someone knock up a site

That just has one page, with a content bit, then styling seperate etc, that I can look at the code, I can't find tutorials
 
For example

I have a page index.php

I have 3 files

_footer.html
_header.html
hello.php

Using the include command I can get only one working at a time, if I include more I get all sorts of errors

index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>


<?php

include('_footer.html')
?>
</body>
</html>

_header.html

<div id="menu">

<ul>

<li><a href="http://micholden.site50.net/rss2htm...TE=http://micholden.site50.net/indexnews.html">Home</a></li>
<li><a href="shopaccess.php">NUFC Shop </a></li>
<li><a href="gallery.html">Gallery</a> </li>
<li><a href="contact2.html">Contact</a><br />
<br />
</li>
</li>
</li>
<li><a href="warddrobe.html">NUFC Wardrobe </a></li>
<li><a href="forum.html">Forums </a></li>
<li><a href="register.html">Register</a></li>
<li><a href="map.html">About Us</a></li>
<li><a href="subscribe.html">Subscribe</a></li>
<li></li>
<img src="images/RSS.jpg" alt="" width="40" height="40" />
<li></li><li></li><li></li></ul>

</div>

_footer.html

<div id="footer">

<p><a href="http://validator.w3.org/check?uri=referer"><img

src="http://www.w3.org/Icons/valid-xhtml10"

alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a> <span class="style2">&copy;<span class="style1"> Newcastle United &nbsp;|&nbsp;</span><a href="loginadmin.php">Admin Login</a><span class="style1"> | </span>&nbsp;<a href="conditions.html">Privacy Statement </a></span><br />

</p>

<p><br />

</p>

</div>
 
I'd just like to say thanks to all who helped/ had input into this thread

Got myself sorted, and can now understand how basic some elements are, no doubt I'll be back though

Once again many thanks for putting up with me:)

I always include this/a variation of this on all my sites in between my header and footer:

Code:
<?
$a = $_GET['a'];
$filename = "$a.php";
if (file_exists($filename)) {
include $filename;
} else {
include 'welcome.php';
}
?>

Easy to add and create new pages and it's also a kind of semi-inbuilt 404.

ie.
domain.com/?a=portfolio would include your portfolio content so long as you have a file named portfolio.php
domain.com/?a=fgkjfkdf would display your main welcome content

Brilliant, cheers, goes into my "useful/amazing webcode" folder
 
Last edited:
Back
Top Bottom