December 20, 201015 yr I need to include the footer of my website via a remote source or something as editing every page (a lot of pages) is a time consuming problem. It would be good to have the header as well but there is a different header for every page but only by one class & a couple lines of code such as CSS and such. Thanks in advance!
December 21, 201015 yr That's a common request and this is the usual answer:- Form one page complete in the normal way with the footer and check that it validates and displays properly. Open up Notepad or a text editor (not Word) and cut the code that repeats in every page completely (as much or as little as you want, without doctype, html, head or body tags) and paste it into Notepad and save as an "include" file called footer.inc in the same folder as the main pages. You then have only one file to edit if the footer changes. Substitute the code you have cut out with PHP code <?php include ("footer.inc"); ?> in the main file and save it with .php filename extension instead of .html or .htm. Do the same with other main pages where the footer repeats and name them with .php extension. You can use .txt, .php, .html or .htm for the "include" file but it distinguishes it as an "include" file in your file list if you use .inc as the filename extension and it's even better if you put all "include" files in a different directory/folder called, say, "includes". You will have to edit the path to suit each page like <?php include ("../includes/footer.inc"); ?> or <?php include ("includes/footer.inc"); ?> if your main pages are in a different folder from the include file, but once set up you won't need to edit it unless you change the folder that the main page is inside. If you use a complete page as an "include" file with .html or .htm for the filename extension the final processed page will have two doctypes, two html tags, two head sections, etc. in an unusual place which is not a good idea so only put the footer code (say the li tags if formed as a list) in the footer.inc file. You can have different "include" files on the same main pages for header and menu and even use "includes" for the parts of the head section that repeat. The PHP code needs to be processed by a server before the result can be seen, either by the hosting service's server just before downloading or by a server like WampServer 2 or XAMPP (which include Apache) on your computer for local viewing, so you won't see the result from the local file on your computer unless you have WampServer 2 or XAMPP installed. Check that your hosting service supports PHP as free webspaces provided by ISPs usually do not. Edited December 21, 201015 yr by Wickham
Create an account or sign in to comment