Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Menu help needed

    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 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 ...

    style.css
    index.html
    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
    Last edited by Tinks; 09-24-2007 at 01:21 AM.

  • #2
    Regular Coder
    Join Date
    Dec 2005
    Location
    Ohio
    Posts
    286
    Thanks
    7
    Thanked 9 Times in 9 Posts
    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 Code:
    <?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.

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Location
    Seattle
    Posts
    153
    Thanks
    5
    Thanked 9 Times in 9 Posts
    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:

    Code:
    <!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">
    <head>
    <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; }
    </style>
    </head>
    
    <body>
    <div id="header">
    	Gary's PHP page
    </div>
    <div id="menu">
    <?php include ("menu.php"); ?> 
    </div>
    </body>
    </html>
    Now I saved this file as phptest.php.

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

    Code:
    <ul>
    	<li>Home</li>
    	<li>Away</li>
    	<li>There</li>
    	<li>Here</li>
    </ul>
    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.

    Gary


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •