Skip to content

Instantly share code, notes, and snippets.

@benjaminfisher
Created May 21, 2012 19:43
Show Gist options
  • Save benjaminfisher/2764204 to your computer and use it in GitHub Desktop.
Save benjaminfisher/2764204 to your computer and use it in GitHub Desktop.
Code to generate dynamic navigation from an array
<?php
$current_page = basename($_SERVER['PHP_SELF']);
$navigation = array(
'About Us' => 'about.php',
'Our Products' => 'products.php',
'Contact' => 'contact.php',
'Testimonials' => 'test.php',
'Blog' => 'blog.php'
);
// Print out the navigation items and links from $navigation
echo "<nav>\n";
echo "\t<ul>\n";
foreach ($navigation as $key => $value) {
echo "\t<li><a href=\"$value\">$key</a></li>\n";
}
echo "\t</ul>\n";
echo "</nav>\n";
?>
@benjaminfisher
Copy link
Author

Still needs if statement to generate current class in the nav list items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment