Skip to content
WJunction - Webmaster Forum

Tutorials & Guides PHP Include (How To Template Your Site)

Status
Not open for further replies.

Jesse

Elite Member
Premium Member
6,389
2009
2,106
These are awesome for making headers/footers/same thing on many pages. It will save you from having to change the same thing on many pages. Rather then doing that, with a few characters of code ( <?php include 'footer.php'; ?> ) you will only need to modify one document to change whatever it is on every page.


Lets assume this is your site and you need to modify the footer. You have over 300 pages. That would be a pain in the ass.

Code:
<html>
<head>
<title>My Site</title>
</head>

<body>

<center>My Site Sections here: Awesome Section 1/Super cool stuff/Even better things</center>
<br><br>
This is such a super cool site that you want to copy it. Look how much info is here in my main section
<br>
<br>
Copyright 2011 My super cool site<br>
</body>

</html>

Every file will need to be made into php

First thing you need to do is make a header.php file. All the info from your header is included in that file.
Code:
<html>
<head>
<title>My Site</title>
</head>

<body>

<center>My Site Sections here: Awesome Section 1/Super cool stuff/Even better things</center>
<br><br>

Next is the footer. Everything that you want to keep in the footer. Usually copyright info or footer links

Code:
<br>
<br>
Copyright 2011 My super cool site<br>
</body>

</html>

w00t! almost there. Now you need to call these pages you just made.

make an index.php file and call up the files you just made. You will see using this will save you a ton of time if you have many pages.
Code:
<?php include 'header.php'; ?>

This is such a super cool site that you want to copy it. Look how much info is here in my main section

<?php include 'footer.php'; ?>

You're not just limited to using this as a header/footer. You can use it for mid-page info as well. I use it for damn near everything.
 

3 comments

ye goog job... you just should have a variable on each page, which tells php how the title of the page should look like... else the title on all pages will be the same... and that's not good for SEO. ;)
 
ye goog job... you just should have a variable on each page, which tells php how the title of the page should look like... else the title on all pages will be the same... and that's not good for SEO. ;)

Yup. Or you can start the header template below the <title></title>. You'd just need to change what's included in the header.php

<html>
<head>
<title>My Site</title>
</head>
<?php include 'header.php'; ?>

This is such a super cool site that you want to copy it. Look how much info is here in my main section

<?php include 'footer.php'; ?>
 
Status
Not open for further replies.

About the author

Jesse
Elite Member · Joined
6,389
Messages
2,106
Reactions
456
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom