The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
Perfect if you don't actually know any php, but are pretty au fait with html.
Simple Tutorial
Problem: You want to have the same text appear on lots of webpages, but you don't want to write it lots of times in different places.
Solution: Use some simple php.
Result: See example web pages.
An 'include' file with the common bits of HTML:
The first thing I do is create a file with all the bits of html which will be common throughout my website. In this case:
The header
The menu
And the footer.
1. Create the include file - it must be a php file, and I called mine Common.php.
Within any php file you can write a mixture of html and php. All the bits of php must be enclosed within these: so the server knows to read it as php.
Each Piece of common html will go in a separate function in the common.php file. A function looks like:
function functionName()
{
... the function code
}
Inside each function you can write the html chunk, so that my common.php file looks like:
<?
function drawTitle()
{
?>
<html>
<head>
<link href=style.css type=text/css rel=stylesheet>
<title>Simple PHP</title>
</head>
<body>
<h1>Simple Web Page</h1>
<?
}
function drawMenu()
{
?>
<p class="menu">
<b>Menu</b><br>
<a href="index.php">MenuItem A</a><br>
<a href="page2.php">Menu Item B</a><br>
Menu Item C<br>
Menu Item D<br>
</p>
<?
}
function drawFooter()
{
?>
<p class="foot">
Joanne Walker ©
</p>
</p>
</body>
</html>
<?
}
?>
Notice how everytime I start some php I have a .
2. So now write each common bit of html within a function.
That's the most difficult bit done.
I then have two pages so far in the site. Each of these will be able to call on the functions in common.php to write chunks of text automatically.
3. Create your first webpage, it must also be a php file. I called mine index.php.
Inside your page the first thing you're going to write is a bit of php to tell it where to look for the common bits of code:
4. Include the common file inside the webpage: at the very top of the file enter:
<?
include("common.php");
and don't forget the semi-colon on the end.
Then you call on the various functions you've written at the right point in the code. This is done by firstly making sure you're in php 'mode' - use
<?
include("common.php");
drawTitle();
drawMenu();
?>
My main webpage text, with words and images, set up as usual.<br>
Here's some text;<br>
And some more text.
<br><br>
And yet more text.
<?
drawFooter();
?>
5. Write the webpage, calling on your common functions wherever you want that html to appear.
6. Write the rest of your web pages in the same way. My page2.php looks like:
<?
include("common.php");
drawTitle();
drawMenu();
?>
Another page with some more text in it.
<?
drawFooter();
?>
I have structured my pages using css only. You can also use this method if you structure your pages with tables (my personal page uses tables), though it becomes slightly more complicated.
For the css I used in this tutoral, see here.
Kev
Perfect if you don't actually know any php, but are pretty au fait with html.
Simple Tutorial
Problem: You want to have the same text appear on lots of webpages, but you don't want to write it lots of times in different places.
Solution: Use some simple php.
Result: See example web pages.
An 'include' file with the common bits of HTML:
The first thing I do is create a file with all the bits of html which will be common throughout my website. In this case:
The header
The menu
And the footer.
1. Create the include file - it must be a php file, and I called mine Common.php.
Within any php file you can write a mixture of html and php. All the bits of php must be enclosed within these: so the server knows to read it as php.
Each Piece of common html will go in a separate function in the common.php file. A function looks like:
function functionName()
{
... the function code
}
Inside each function you can write the html chunk, so that my common.php file looks like:
<?
function drawTitle()
{
?>
<html>
<head>
<link href=style.css type=text/css rel=stylesheet>
<title>Simple PHP</title>
</head>
<body>
<h1>Simple Web Page</h1>
<?
}
function drawMenu()
{
?>
<p class="menu">
<b>Menu</b><br>
<a href="index.php">MenuItem A</a><br>
<a href="page2.php">Menu Item B</a><br>
Menu Item C<br>
Menu Item D<br>
</p>
<?
}
function drawFooter()
{
?>
<p class="foot">
Joanne Walker ©
</p>
</p>
</body>
</html>
<?
}
?>
Notice how everytime I start some php I have a .
2. So now write each common bit of html within a function.
That's the most difficult bit done.
I then have two pages so far in the site. Each of these will be able to call on the functions in common.php to write chunks of text automatically.
3. Create your first webpage, it must also be a php file. I called mine index.php.
Inside your page the first thing you're going to write is a bit of php to tell it where to look for the common bits of code:
4. Include the common file inside the webpage: at the very top of the file enter:
<?
include("common.php");
and don't forget the semi-colon on the end.
Then you call on the various functions you've written at the right point in the code. This is done by firstly making sure you're in php 'mode' - use
<?
include("common.php");
drawTitle();
drawMenu();
?>
My main webpage text, with words and images, set up as usual.<br>
Here's some text;<br>
And some more text.
<br><br>
And yet more text.
<?
drawFooter();
?>
5. Write the webpage, calling on your common functions wherever you want that html to appear.
6. Write the rest of your web pages in the same way. My page2.php looks like:
<?
include("common.php");
drawTitle();
drawMenu();
?>
Another page with some more text in it.
<?
drawFooter();
?>
I have structured my pages using css only. You can also use this method if you structure your pages with tables (my personal page uses tables), though it becomes slightly more complicated.
For the css I used in this tutoral, see here.