Sunday 5 June 2011

How do I change website content without touching every page?

I have a header content I use on every page. This includes a banner, navigation and links to facebook, twitter and myspace. The script also includes the page styles. Is there a way to put all this into a single web document and put a code in place so it automatically inserts it into the page? I want to be able to freely make changes to some of that without editing every single page.|||Try the PHP function include().





Your site should look like this:





File index.php


%26lt;html%26gt;





%26lt;body%26gt;





%26lt;div id=%26quot;header%26quot;%26gt;%26lt;/div%26gt;


%26lt;div id=%26quot;navigation%26quot;%26gt;%26lt;/div%26gt;


%26lt;div id=%26quot;content%26quot;%26gt;





%26lt;?php


$site = $_GET[%26quot;site%26quot;];


include(%26#039;homepage/%26#039;.$site.%26#039;.php%26#039;);


?%26gt;





%26lt;/div%26gt;


%26lt;/body%26gt;





And your links should look like this:


%26lt;div id=%26quot;navigation%26quot;%26gt;





%26lt;a href=%26quot;homepage/index.php?site=home%26quot;%26gt;%26lt;/a%26gt;


%26lt;a href=%26quot;homepage/index.php?site=about%26quot;%26gt;%26lt;/a鈥?br>

%26lt;/div%26gt;








Now create the files:


homepage/home.php with your content in it.





The link will now tell the file index.php which site to load, and index.php will simply insert the content of the included file.|||Best way to do this it to use a programming language such as PHP.





www.php.net





I use this on my websites. It allows you to mix code and HTML.


Every page has to have a php extension and your web server has to support PHP scripting (most do).





You would have your header file saved and then use the


%26lt;?php include(%26#039;filename.inc%26#039;); ?%26gt;


line to get your standard header and footer into any page.





Wil .