How to include php headers and footers on html site
# August 26, 2012 at 1:22 pm
Alright, so I built my site completely using html and css. I am finding that as I’m updating it along the way it is becoming rather laboursome to have to go to every single .html page to modify the header and footer code just so it will function the same. I know you can simplify this using php so you only have to modify the one file and it will automatically update for every page. So I guess my question is how do I go about doing that?# August 26, 2012 at 3:37 pm
So let’s say my I change my index.html to index.php. I copy all of my header code and paste it into a header.php file and then add this code to the top of every page?
< ?php include 'header.php'; ?>
Will the header code then look something like this?
< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
I tried experimenting with that and it won’t let me preview the index.php file (probably because it’s not a webpage)# August 26, 2012 at 4:05 pm
Is there a reason you’re using XHTML? You can make it even more simple by using the HTML5 doctype (add this to your header.php file):
< !doctype html>
I also noticed your title. You’re going to need a loop to determine the title of the page.
and then to include it for every page, just paste this in your index file(s)
< ?php include 'header.php'; ?># August 26, 2012 at 5:01 pm
Alright, MAMP is working properly, but I’m having a problem. I changed my index.html to index.php and placed it in the mamp/htdocs folder. I tested to see if it worked by placing random text into the index.php file and it appeared in the browser so Woot! But when I paste my html code that I had before the page remains completely blank. Not even any < p >text< /p > is showing up. I’m not sure what I should do from here
You must be logged in to reply to this topic.