You are seeing this very light version of the page, as you are using an outdated browser! is done in XHTML 1.0 and supports CSS 2.0, please upgrade your browser if you want a better version of this site.

Thank you, please help us developers keep up with the industry rather than patching our code for outdated applications.

open or close right navigation

Flexible navigation with PHP

written by:Christian Heilmann on 26.04.2002
Jump to page: 1  2  3  4  5  or read all on one page

The nav.php script

1:     $sites=explode(",","about_us,contact,work_examples,links");
2:     $issite=explode("/",$HTTP_SERVER_VARS['REQUEST_URI']);
3:     $issite=explode(".",$issite[sizeof($issite)-1]);
4:     for ($i=0;$i<sizeof($sites);$i++){
5:         $d=ucwords(str_replace("_"," ",$sites[$i]));
6:         if ($sites[$i] == $issite[0]){
7:             echo "<b>$d</b>";
8:             }
9:         else {
10:             echo "<a href=\"".$sites[$i].".php\">";
11:             echo $d;
12:             echo "</a>";
13:             }
14:         if ($i < sizeof($sites)-1){echo " | ";}
15:         }

line 1 defines all the entries of the navigation, make sure that these values match the actual filenames without extensions.

line 3 retrieves the name of the current site for comparison.

line 4 starts looping over all the entries.

line 6 compares the currently displayed page with the one of the list, and displays the highlighted name without underscores. Each word gets converted to start with an uppercase character (as defined in line 5).

lines 10-12 display a link for all the other sites of our list.

line 14 puts a pipe character ("|") in between the links, but not after the last one.

And that is it! As simple as that. If you now create a new page with the template, you simply add it to the list in line 1 and it will display throughout the whole site.

With a bit of skill and the right naming conventions you can also do a graphical rollover navigation with the same script.

Now, download this demo page and have a look at it.

Table of contents:

The navigation woe
How to gain flexibility
The page template.
The nav.php script
Download and known issues

Back to top




Click to decrease fontsizeClick to increase fontsize



sponsored by :



Help, donate via paypal




Link to us

copy the code here:

Powered by EasyCMS