/ Published in: PHP
URL: www.jakepaint.com/menufun/
This menu reads a directory and spits out the contents as an expanding menu. Great for a dynamic site with quick changing content.
Expand |
Embed | Plain Text
<?php function getfileinfo($thedirectory) { $files = scandir($thedirectory); //THIS TAKES OFF THE FILENAME EXTENSION FOR A CLEANER MENU. THIS IS FOR .txt files //THIS REMOVES THOSE 1ST TWO PESKY DOTS THAT SHOW UP " . " & " .. " return($namelisting); ?> //THIS IS THE DYNAMIC MENU <ul> <li><a href="breakfast.php">Breakfast</a> <?php if ($page == "breakfast") { echo '<ul>'; $breakfastitems = getfileinfo("content/breakfast/"); foreach ($breakfastitems as $value) { } echo '</ul>'; } echo '</li>'; ?> </li> <li><a href="lunch.php">Lunch</a> <?php if ($page == "lunch") { echo '<ul>'; $lunchitems = getfileinfo("content/lunch/"); foreach ($lunchitems as $value) { } echo '</ul>'; } ?> </li> </ul> //THIS GOES INTO THE PAGE //ASSUMING THE .TXT FILES ARE IN /CONTENT dir <?php //ADD THE EXTENSION BACK ON $pagecontent = "content/" . $page . "/" . $_GET['food'] . ".txt"; include($pagecontent); } else { echo 'I like to eat breakfast.'; } ?>
You need to login to post a comment.
