1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP How to code a menu to avoid repetitive changes

Discussion in 'Web Development' started by Briankangaroo, Jul 23, 2010.

  1. Briankangaroo

    Briankangaroo New Member

    Hi, I am hoping for your two cents on how to build the menu of a portfolio site that will have 20 or so projects demonstrated without having to change the menu of 20 some pages each time I add a new piece. I built my last web site years ago using frames to have a static menu and simply swap out the content frame. That way a new menu item and content page was added once, and it was done. Frames are not without problems and I'm sure there is a better option. Ideas? I'm searching for the most conventional, proper way to go about it.

    Do I code a menu into a CSS file that is called into action on each page?
    Do I make just one Portfolio page and use special code to swap out the different project info as their menu buttons are pressed giving the illusion of many different pages?
    I've been pulling my remaining hair out learning CSS lately, so I might as well learn whatever the "right" way to do it its. :)
     
  2. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    you will need to learn a little php
    create a page called menu.php and put all that you need in there.
    on every page you normally would code your menu information, you now will call up the menu.php file.
    now you only have to work with one file when you want to change something.

    This should help spare your hair - now you are on track - go forth an Google.
     
  3. Briankangaroo

    Briankangaroo New Member

    Much thanks you sir. I've been on google for 2 days trying every search string to find this answer. I'm on it.
     
  4. Briankangaroo

    Briankangaroo New Member

  5. Briankangaroo

    Briankangaroo New Member

    I was successfully able to cut the entire "div" containing a menu from a template and paste it into a blank php file named menu.php. I then had to replace the code I extracted with the proper "include" command. I changed the file names to .php from .html. I also had to remove the <?xml tag and replace it with a standard <html> tag before it would work and et viola! (It only works on the server since locally viewed, it has no server to execute the swap) I kiss your feet sir! This may simple to you, but there just aren't any articles online about best coding practices for menus that I could find. I now feel like I will be able to expand the template into the 20 or so portfolio pages I need without making an updating nightmare for myself each time I want to add a new page.

    One question: I have been able to successfully use the php files as described above, but will removing the <?xml...> tag and replacing with <html> have any undesired results down the road?
     
  6. Arkangel

    Arkangel New Member

    WOW! really thanks for posting the answer mate! i read the tutorial and now i can make it nicely too!!!