Forum Moderators: open
I want to have a simple, one level, menu displayed on all 80 pages of my site. The menu items will change periodically - new items added, some removed, etc... What is the best way to create this menu so I don't have to update all 80 pages? FYI: I'm not too knowledgeable in all the scripting languages. Thank you.
<html>
<head>
<title></title>
</head>
<body>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/somedirectory/mymenu.php');?>
</body>
</html>
Then create mymenu.php which can simply conatian some text, html, whatever....:
TEST
Upload both and make sure mymenu.php is located at somedirectory/mymenu.php
When you load mypage.php in a browser it should have the text "TEST".
PHP is pretty common but if you don't have it you will have some type of server side includes and the directions will be different.
<!--#include file="mymenu.txt" -->
or if mymenu.txt resides in a directory,
<!--#include virtual="/directory/mymenu.txt" -->
Normally this applies only to files with a .shtml extension so the server knows what files to parse to look for SSI commands, and also SSI must be enabled on your server. You can change your server configuration to parse ALL plain text files, or all files with an .htm, .html, or .shtml extension. Have your server administrator set it up, then all you need to do is experiment with SSI's. You can test if SSI's are already active on your server:
1. Create a file with an SSI directive
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>SSI test</title>
</head>
<body>
<p>test</p>
<!--#include file="mymenu.txt" -->
</body>
</html>
Save this file as test.shtml.
2. Create a plain text file
<p>This is my include file</p>
And name it mymenu.txt.
3. Upload them both to the same directory on your server and browse to the page. If you see both "test" and "This is my include file" on the page, SSI's are up and running.
<?php include 'mymenu.php';?>
The difference being that is a relative path and will only work for files in the same directory. The original one I posted is a absolute path and will work on any file no matter what it's location is.
The benefit of using PHP for includes is just the tip of the iceberg as far as what you can do with PHP.