This tutorial teaches you how to create a PHP website template.
What Will You Learn?
- To create a PHP template.
- To use PHP Includes.
- A little bit of HTML and CSS
Create a new folder on your computer and name it anything you want. In this example, I’ll name the folder, ‘Area51’ .
In the folder, create a new folder, named, ‘includes’ . Then, create a file in the folder, ‘Area51’ , named, ‘index.php’. If your website uses CSS, then you should create a CSS file in the folder, ‘Area51’.
Once all of the above has been completed, it’s time to look at the website’s source code. I’ve written up a quick source code to be used for this example. Warning! : The design is ugly and might hurt your eyes…
HTML :
iWebBuddy.com
Hello World! I’m new to iWebBuddy.com , are you?
CSS :
#header {
width: 100%;
height: 100px;
background-color: #00FFFF;
}
#nav {
height: 35px;
background-color: #33FF00;
text-align: center;
}
#nav ul {
margin: 0px;
color: #330066;
text-decoration: none;
padding-top: 0px;
padding-left: 20px;
padding-right: 0px;
padding-bottom: 3px;
}
#nav ul li {
display: inline;
padding: 0px;
text-align: center
}
.content {
background-color: #66CC66;
text-align: left;
width: 100%;
font-size: 0.9em;
color: #99FF33;
padding-top: 5px;
padding-bottom:15px;
}
#footer {
background-color: #33FF00;
height: 100px;
padding-top: 10px;
width: 100%;
}
.copyright {
text-align: center;
color: #FFFF00;
font-size : 0.8em;
}
Create a new CSS File called, ‘style.css’ and add the above CSS to the style sheet.
Now, it’s time to separate pieces of the template and use PHP Includes.
In your ‘includes’ folder, create 3 new PHP files. I’ve listed these files below :
- header.php
- nav.php
- footer.php
Now, it’s time to remove pieces of the template from ‘index.php’ and add them to separate files.
Find :
iWebBuddy.com
And add it to your ‘header.php’ file, in the ‘includes’ folder in the ‘Area51’ folder.
Find :
And add it to your ‘nav.php’ file, in the ‘includes’ folder in the ‘Area51’ folder.
Find :
And add it to your ‘footer.php’ file, in the ‘includes’ folder in the ‘Area51’ folder.
Once you’re done, go back to the ‘Area51’ folder and open the ‘index.php’ file. Remember, you’ve removed a few codes from the file. Now, replace those parts with the code below :
Replace the symbol ‘???’ with the file name of your PHP files from the ‘includes’ folder. Then add this code to the codes that you’ve removed from index.php and save your work.
Congratulations! You’ve created a PHP website template. Now, upload all of the files to your website.
Summary :
Basically, you’re making it easier to edit your files, instead of editing hundreds of files just to insert a link to one of your web pages that is seen on almost your whole website.
Troubleshooting :
Q: Why isn’t NotePad not opening .php files?
A: Upgrade to TextPad.
Leave a Reply