| Author |
Message |
pharmer4 Metallica Fanatic

Joined: 16 Aug 2005 Posts: 2136 Location: Deniliquin, Australia
|
Posted: Tue Jan 29, 2008 2:44 pm Post subject: I want to have a specific region appear on all my pages . . |
|
|
G'day
I want to have a specific piece of html appear on every page on my site.
I want to be able to edit this piece of html at will, without needing to go back and change all 400+ pages on my site.
Can this be done with php?
ie could a piece of php be written than contains the code I want to be able to edit and show on every page, and then on the page where I want that code to appear, have a piece of pho code that calls on the php file to display the html in question?
If so, is there anyone here who would feel like writing an example of what I need to do - if you do, just use XXXXXX as the html code that I am interested in appearing on all my pages.
I would need the following code . . . .
1) the code for a page (or whatever is appropriate) that contains the html code that I want to appear on my pages (say the code I am interested is XXXX)
2) the code that would appear in my pages at the point where i want XXXX to appear
3) anything else that is necessary to do this
thanks guys _________________ For Metal and Rock interviews and reviews, go to www.heavymetalnation.com - You can Contribute too if you want!
http://deniliquin.myminicity.com |
|
| Back to top |
|
| |
Scott tutorialtoday.com

Joined: 24 Mar 2005 Posts: 2747 Location: Mississauga, Ontario
|
Posted: Tue Jan 29, 2008 3:04 pm Post subject: |
|
|
This is very easy and there are tons of tutorials on it but what you can do is...
Imagine the code is in a file called "include.html", then you would put it in the same directory as the file(s) it will be used in, and on the PHP pages you want it, just put:
| Code: | <?php
include("include.html");
?> |
If you want to put the includes in a separate directory to avoid confusion then for the include() just put like "includes/invlude.html" _________________ TutorialToday |
|
| Back to top |
|
| |
Rashy Lifeless Person
Joined: 25 Sep 2006 Posts: 797
|
Posted: Tue Jan 29, 2008 3:32 pm Post subject: |
|
|
Just make sure that when you use the include function you use the right path. I've got it wrong many times
Lets say you have your base directory: /
Inside / is index.php, about.php, contact.php and the directories articles/ and includes/
so to get that piece of code from index.php, you would use include('includes/code.html'); but if you want to get that piece of code from a file that is inside /articles/ (say /articles/metallica.php) then you have to use include('../includes/code/html');
Of course using PHP like this means that all of your current pages written as basic html will have to have their names changed to whatever.php and you will have to insert include('path/includes/code.html); into every single file. If you want to automatically update all of your files, then I imagine there is a way to use PHP to "batch process" the files to replace to contents of code.html with the include function. That would have to be custom written though. _________________ Rashy! |
|
| Back to top |
|
| |
pharmer4 Metallica Fanatic

Joined: 16 Aug 2005 Posts: 2136 Location: Deniliquin, Australia
|
Posted: Wed Jan 30, 2008 6:10 am Post subject: |
|
|
thanks guys.
I need to change all my html to php anyway to install a comments code I just received, so that is not problems, I just wanted to be able to do something that would prevent me needing to ever do it again!!!!
the particular code I want to have show up using php will have simple table with "find us on the web" in the top cell, and in the second line, cells filled with graphics and links back to the various social sites I have created profiles on, such as myspace, bebo, etc etc. Since these things are coming out all the time, with varying popularity, I wanted to be able to add new ones and delete defunct ones at will, without needing to manually change every blood page! _________________ For Metal and Rock interviews and reviews, go to www.heavymetalnation.com - You can Contribute too if you want!
http://deniliquin.myminicity.com |
|
| Back to top |
|
| |
pharmer4 Metallica Fanatic

Joined: 16 Aug 2005 Posts: 2136 Location: Deniliquin, Australia
|
Posted: Wed Jan 30, 2008 6:44 am Post subject: |
|
|
works well guys, although i've found that it works best if the file containing the code in question is a php file. _________________ For Metal and Rock interviews and reviews, go to www.heavymetalnation.com - You can Contribute too if you want!
http://deniliquin.myminicity.com |
|
| Back to top |
|
| |
ClickFanatic Est. 2005

Joined: 18 Jan 2005 Posts: 4685 Location: 37°45'18.24"N 14°59'42.9"E
|
Posted: Wed Jan 30, 2008 8:38 am Post subject: |
|
|
You can also use simple server side includes, but that does require the files to end in .shtml. Although you can configure plain .html files to be parsed as .shtml.
To do so, put:
| Code: | | AddHandler server-parsed .html |
in a .htaccess (or use cPanel to configure the Apache handler).
Including a file is done by adding:
| Code: | | <!--#include virtual="header.html"--> |
Somewhere in the page. The virtual attribute is the filename relative to the document root.
The advantage of server-parsed HTML when you only need to include static content is that it is much faster than PHP.
So unless you are already using PHP, server-parsed HTML is a good option. _________________ If you can read this, my post is on an alternating background. |
|
| Back to top |
|
| |
pharmer4 Metallica Fanatic

Joined: 16 Aug 2005 Posts: 2136 Location: Deniliquin, Australia
|
Posted: Thu Jan 31, 2008 2:35 am Post subject: |
|
|
speed is definately something that I am interested in, BUT, my level of understanding means that reading that statement you made there does not make complete sense to me . . .
Basically, I don't know how to make the code you put up there specific for my site etc. _________________ For Metal and Rock interviews and reviews, go to www.heavymetalnation.com - You can Contribute too if you want!
http://deniliquin.myminicity.com |
|
| Back to top |
|
| |
Ayana Master Poster
Joined: 04 Nov 2006 Posts: 205
|
Posted: Thu Jan 31, 2008 7:01 am Post subject: |
|
|
i tried using virtual a couple of days ago but it came up with an error about undefined function so i'm not sure if it works properly _________________
 |
|
| Back to top |
|
| |
ClickFanatic Est. 2005

Joined: 18 Jan 2005 Posts: 4685 Location: 37°45'18.24"N 14°59'42.9"E
|
Posted: Thu Jan 31, 2008 7:02 am Post subject: |
|
|
| Code: | | <?php include('file.ext'); ?> |
Can only be used by PHP-parsed files (i.e. files ending in .php). You could configure HTML files to be parsed by PHP, but that, in general, would be a waste of (shared) server resources.
Additionally, 'file.ext' is always relative to the currently requested file unless you provide an absolute path (i.e. relative to the server root directory, not your website root directory).
This can be considered as inconvenient when all you want is a simple include.
| Code: | | <!--#include virtual="file.ext"--> |
Using this has some advantages.
The PHP parser doesn't have to be loaded, saving resources that you don't really need for an include anyway.
"file.ext" is relative to your website root (i.e. the public_html folder). Example:
If your website is at http://www.example.com/ then the above code would include the file http://www.example.com/file.ext (i.e. public_html/file.ext).
| Code: | | <!--#include virtual="subdir/file.ext"--> |
This would include the file http://www.example.com/subdir/file.ext (i.e. public_html/subdir/file.ext).
This is much more consistent than PHP's include (which becomes confusing when the files are spread across different directories and relative paths are used).
Since this feature is normally only available to .shtml files and your site is using .htm files you will have to tell the server that you want those to be 'server-parsed' as well (unless you want to rename the files in question to .shtml). To do this in cPanel: Site management -> Apache Handlers, for Extension enter .htm, for Handler enter server-parsed, -> Add
Does it make more sense now? _________________ If you can read this, my post is on an alternating background. |
|
| Back to top |
|
| |
|
|
|