Question:

How do I create a structured menu in PHP, with sub menus that display in the appropriate sections?

by  |  earlier

0 LIKES UnLike

I have my site, which has a menu on the side bar. For arguments sake, I have the following sections:

courses

resources

about

links

contact

Contact does not have a relevant sub menu, but the others do.

How can I get the about sub menu to appear on all the pages in about, the resources sub menu to appear on all the pages in resources, etc ... AND, if I want a third level, how do I get these menus into their relevant pages?

I don't want to create a menu on each page. I know it can be done using a Content system, but I don't know how it can be done in PHP. Any help?

 Tags:

   Report

2 ANSWERS


  1. you need to use javascript to create the menu. Php will not help you. PHP usually works in the background. right now you need something like a collapsable menu that links to your html or php pages.


  2. Hi!!

    Firstly I think you are getting a little confused on what php code actually does, so I will try and explain.

    Here is a basic html/javascript based menu:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    <html>

    <body>

    <script type="text/javascript">

    at_attach("menu_parent", "menu_child", "hover", "y", "pointer");

    </script>

    <div id="menu_parent">Main Menu</div>

    <div id="menu_child">

    <a href="#">Item 1</a>

    <a href="#">Item 2</a>

    <a href="#">Item 3</a>

    </div>

    </body>

    </html>

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Now php code is what the server processes before sending the html code to you. So as an example you could get it to check if someone is logged into the website or not and show them a different menu depending on this. eg:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    <html>

    <body>

    <script type="text/javascript">

    at_attach("menu_parent", "menu_child", "hover", "y", "pointer");

    </script>

    <?php

    if ($_COOKIE['mywebsitecookie'] == "LoggedIn") {

    ?>

    <div id="menu_parent">Logged In Menu</div>

    <div id="menu_child">

    <a href="#">Logged in Item 1</a>

    <a href="#">Logged in Item 2</a>

    <a href="#">Logged in Item 3</a>

    </div>

    <?php

    } else { // (If they are not logged in)

    ?>

    <div id="menu_parent">Logged out Menu</div>

    <div id="menu_child">

    <a href="#">Logged out Item 1</a>

    <a href="#">Logged out Item 2</a>

    <a href="#">Logged out Item 3</a>

    </div>

    <?php

    }

    ?>

    </body>

    </html>

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Everything between the "<?php" and "?>" tags is code that is processed by the server. So in this case it will check if the cookie value "mywebsitecookie" is equal to "LoggedIn". If it is equal then it will transmit the logged in menu to your browser. If not (the "} else {" ) it will send the logged out menu to your browser instead.

    This is only a basic menu to show how it works but there are a load of different javascript menus to choose from at dynamicdrive. See:

    http://www.dynamicdrive.com/dynamicindex...

    Hope this helps, I try and explain as best as possible but its sometimes confusing as you have two different types of code on one page.

    Stevie.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.