Navigation Function (in PHP and ASP)
In the websites I build, I often use a function to do navigation that "toggles" based on where we are in the site. These are those functions, in two languages: PHP and ASP.
ASP Source Code
<% REM -------------------------------- function navToggleState(my_url, title, linktext, my_class) REQUEST_URI = Request.ServerVariables("SCRIPT_NAME") theRequest = REQUEST_URI theLink = my_url firstTwoCharsRequest = Mid(theLink,7,2) firstTwoCharsLink = Mid(theRequest,7,2) If (REQUEST_URI = theLink) Then RESPONSE.WRITE "<span class=""" & my_class & """ title=""" & title & "- YOU ARE HERE."">" & linktext & "</span>" Elseif (firstTwoCharsLink=firstTwoCharsRequest) then RESPONSE.WRITE "<a href=""" & my_url & """ title=""" & title & """ class=""" & my_class & "Active"">" & linktext & "</a>" Else RESPONSE.WRITE "<a href=""" & my_url & """ title=""" & title & """ class=""" & my_class & """>" & linktext & "</a>" End If End Function REM -------------------------------- REM usage: REM navToggleState("/", "The WebSanDiego.org Home Page", "WebSanDiego", "nav"); REM results in REM <span class="nav" title="The WebSanDiego.org Home Page- YOU ARE HERE">WebSanDiego</span> REM or REM <a href="/" class="nav" title="The WebSanDiego.org Home Page">WebSanDiego</a> REM -------------------------------- %>
PHP Source Code
<?php // -------------------------------- function navToggleState($my_url, $title, $linktext, $my_class) { global $REQUEST_URI; $theRequest = $REQUEST_URI; $theLink = $my_url; $firstTwoCharsRequest = substr($theLink,6,2); $firstTwoCharsLink = substr($theRequest,6,2); if ($REQUEST_URI == $theLink) { echo "<span class=\"$my_class\" title=\"$title - YOU ARE HERE.\">" . $linktext . "</span>"; } else if ($firstTwoCharsLink==$firstTwoCharsRequest) { echo "<a href=\"$my_url\" title=\"$title\" class=\"$my_class" . "Active" . "\">$linktext</a>"; } else { echo "<a href=\"$my_url\" title=\"$title\" class=\"$my_class\">$linktext</a>"; } }; // -------------------------------- // usage: // navToggleState("/", "The WebSanDiego.org Home Page", "WebSanDiego", "nav"); // results in // <span class="nav" title="The WebSanDiego.org Home Page- YOU ARE HERE">WebSanDiego</span> // or // <a href="/" class="nav" title="The WebSanDiego.org Home Page">WebSanDiego</a> // -------------------------------- ?>