« Current state of navigation | Main | SONOFA... »

July 29, 2004

More current state of navigation

A completely dynamic version that uses an associative array to store link text and URL. Very good for large sites that have a lot of navlinks.

The real time saver is calling the array and link output as includes, i.e., your navigation is contained in one or two include files and can be updated on a global basis (much like stylesheets).

A completely dynamic version that uses an associative array to store link text and URL. Very good for large sites that have a lot of navlinks.

The real time saver is calling the array and link output as includes, i.e., your navigation is contained in one or two include files and can be updated on a global basis (much like stylesheets).

<?php // get current URL $current_URL = $_SERVER['REQUEST_URI']; // THE FOLLOWING CAN BE PUT IN AN INCLUDE // include('navitems.php'); // array of nav links // syntax: linktext => URL $navitems = array( "home" => "/index.php", "about" => "/about_us/", "products" => "/products/", "support" => "/support/", "contact" => "/contact_us/", "admin" => "/admin/", ); // THE FOLLOWING CAN BE PUT IN AN INCLUDE // include('navoutput.php'); while ( list($id, $directory) = each($navitems) ) { $class = $id . "_class"; if ( eregi($directory, $current_URL)) { $$class = ' class="current"'; } else { $$class = ''; } // style your navigation as you see fit // this is a basic example print ' <a href="'.$directory.'" title="'.$id.'"'.$$class.'>'.$id.'</a><br /> '; } ?>

Posted by Brian Tully at July 29, 2004 05:02 PM

Trackback Pings

TrackBack URL for this entry:
http://www.tullyvision.com/mt/mt-tb.cgi/4

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?