SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php Menus, How to?

    Hi,
    I would like to have a submenu on a site I am building displayed when a user clicks a main navigation link. For example, the menubar is on two rows, one main row and another for sublinks. If I click on one option in the top row, then I get links for that in the bottom row.

    I wanted to have my menu inserted into each page so that I can modify only one file to change my menu across the entire site. Is PHP suitable for this and can anyone point me to resources for developing such a system? Also is it possible to do this without using a database?

    Thanks a lot,
    Umesh

  2. #2
    SitePoint Zealot LiamW's Avatar
    Join Date
    Mar 2003
    Location
    Hamilton, Ontario
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To include your menu into every page you can use php's include function.

    PHP Code:
    <?
    include('full/path/to/menu.html');
    ?>
    Just put that code where you want the menu to show.

    As for your other question, it is possible to do what you want though javascript might be a better way. It's up to you.

    When a user clicks on a main link does it send them to a new page and show the submenu or does it just show the new submenu?

  3. #3
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. The menu will send them to a new page and show the submenu links.

  4. #4
    SitePoint Zealot LiamW's Avatar
    Join Date
    Mar 2003
    Location
    Hamilton, Ontario
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok than to do it in php you would append a variable to each menu link like so

    <a href="somefile.php?show=submenu">Linkname</a>

    then where your sub menu is to show up you would do a simple if statement like so

    PHP Code:
    if ($_GET['show'] == 'submenu')
    include(
    'full/path/to/submenu.html'); 

    $_GET will only work if you are running php>=4.1
    If not use $HTTP_POST_VARS

    That should do it I believe.


Bookmarks

Posting Permissions

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