View Full Version : Menu help needed

09-24-2007, 02:15 AM
Well I'm creating a website however I just want the layout and navigation bar to stay the same on each page. This way when I update the site, I only have to do it once. I heard you needed PHP for this, so I bought it. Now I have no idea how to make it work :eek: Tried reading tutorials but they don't help me, it simply just goes straight through my head. However I think you can also use HTML to fix this problem too, I remember ages ago someone once did it for me really easily. I wish I still had a copy of that code!

If it helps, my site has a ...

menu.php <----This is what I put the code for the navigation however it didn't work when i followed a tutorial.

The site I'm working on is called innocent-envy.com - I haven't made the layout yet or anything I just need to understand how to do the links first. When I tried using the PHP it just took the menu away =P
It was only a simple one with links, no special buttons or anything. I just want it to work :(

If anyone could help me with this problem I would appreciate it so much =D

09-24-2007, 05:36 AM
It would help a lot if we could see your code, but I can give you some tips.

From what you are describing, you may want to code out a sample page that contains all of your information and your navigation bar and then remove the navigation bar and put that code into your php file. In place of the menu's code on the page, put

<?php include ("menu.php"); ?>
instead. When the page renders, it will include the code that is in the menu.php file. To make the layout consistent, you would just need to use CSS. Post more information if you need further help.

09-24-2007, 09:29 AM
To clarify something in regards to PHP, you need to save your main web page with the extension .php, or the web browser will not render it properly. Here is a basic example page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
#header {background-color:#FFFF00; color:#2A3FAA}
#menu {float:left; }

<div id="header">
Gary's PHP page
<div id="menu">
<?php include ("menu.php"); ?>

Now I saved this file as phptest.php.

I also have a file called menu.php, the complete contents are like this:


You'll notice the file contains no DOCTYPE, no other tags or styles. Just the stuff I want to appear in the menu section of my main page. Now when I preview the phptest.php file in my browser, the menu gets inserted dynamically. Make sure your computer is configured as a testing server, or you will have to upload your pages to a live host to see them.