Dynamic PHP Menu - Tutorial

Discussion in 'PHP' started by ehlokoen, Dec 20, 2006.

  1. #1
    I decided to make a dynamic menu. The menu will be created based on a folder with the pages for your website. If the folder contains Downloads(.php), About(.php) etc. the page will list them. Now I thought, let's share the script, and describe some functions :)

    <html>
    <head>
    
    <style>
          table.menu {position:absolute;left:25;top:450;color:yellow}
          a {text-decoration:none;color:white;font-family:verdana;font-size:9}
          iframe.body {position:absolute;left:275;top:300;color:yellow}
    </style>
    
    </head>
    
    <body bgcolor = "#888888">
    
    <table border = 1 class = "menu" bgcolor = "#800000">
          <tr height = "350">
            <td width = "175">
    
    
    <?php
    $handle=opendir('./menu'); //select the directory where your menu files will be
    while (false!==($file = readdir($handle))) {
       if ($file != "." && $file != ".." && substr($file, -4) == ".php") { // change .php in the extension you use
    
           do
           {
    
       $file2 = substr_replace ($file, '', -4); // if your extension (with the dot) is longer then 4, edit this
       echo "<a href = \"menu/$file\" target = \"links\">$file2</a>"; //The link, based on the file
       echo '<br>'; // start a new line
    
           } while ($file != 0);
    
       }
    
    }
    closedir($handle); //close the menu directory
    ?>
            </td>
          </tr>
    </table>
    
    <iframe name = "links" src = "about:blank" class = "body" width = "900" height = "500" marginwidth = "0" marginheight = "0">It seems your browser doesn't show frames!</iframe>
    
    </body>
    </html>
    PHP:
    In this tutorial I used an iframe and a menu, but this aint needed! Almost every layout will work.

    Maybe the scripts seems not really easy, but hey trust me: it is easy to edit. It's commented :)
    If there are any questions about this script, say it here, or pm me.

    Have fun with it :)
     
    ehlokoen, Dec 20, 2006 IP
  2. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    gr8 script to share...
     
    weknowtheworld, Dec 21, 2006 IP
  3. ehlokoen

    ehlokoen Peon

    Messages:
    161
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks :) I've made that a few weeks ago, and just found it back, so I thought I could share it :D
     
    ehlokoen, Dec 21, 2006 IP
  4. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    any more..?
     
    weknowtheworld, Dec 22, 2006 IP