Hi folks,
My dynamic menu code:
Code: Select all
<div id="container">
<ul id="menu">
<?php
##########################
## navigation.inc.php ##
##############################################################################
## Use this code to display a smart/dynamic PHP/CSS menu on your website: ##
##############################################################################
///////////////////////////////////////// function crtLinks():
///////////////////////////////////////// This function will create links and add the "current" CSS class to the current page link by comparing "$page" and "$pages[$link]":
function crt_links($link) {
# Create array and pop with items to be stripped from URL:
$locate = array("/folio/", "index.php");
# $pages pops an array with links set by webmaster:
$pages = array (
"Home" => "index.php",
"About" => "index.php?display=about",
"Work" => "index.php?display=work",
"Resume" => "index.php?display=resume",
"Code" => "index.php?display=code",
"Contact" => "index.php?display=contact",
"Forum" => "index.php?display=forum",
"Guestbook" => "index.php?display=guestbook",
"Links" => "index.php?display=links",
"Dotcoms" => "index.php?display=dotcoms"
); // Add more links here.
# $titles pops an array with link-related titles set by webmaster:
$titles = array (
"Home" => "[Ambiguism -- Home]",
"About" => "[Ambiguism -- About]",
"Work" => "[Ambiguism -- Work]",
"Resume" => "[Ambiguism -- Resume]",
"Code" => "[Ambiguism -- Code]",
"Contact" => "[Ambiguism -- Contact]",
"Forum" => "[Ambiguism -- Forum]",
"Guestbook" => "[Ambiguism -- Guestbook]",
"Links" => "[Ambiguism -- Links]",
"Dotcoms" => "[Ambiguism -- Dotcoms]"
); // Add more titles here.
# Find the current page(s) url:
$page = str_replace($locate[0], "", $_SERVER['SCRIPT_NAME']) . str_replace($locate, "", $_SERVER['REQUEST_URI']);
# Make $link lower-case for style-sheet "id" reference:
$lower = strtolower($link);
# Compare URL to links for display of current and non-current nav links:
if($page == $pages[$link]) { // If page is current page, set CSS class to "selected":
echo '<li id="'.$lower.'"><a class="selected" href="'.$pages[$link].'" title="'.$titles[$link].'">'.$link.'</a></li>'."\n";
} else { // Set to non-current style
echo '<li id="'.$lower.'"><a href="'.$pages[$link].'" title="'.$titles[$link].'">'.$link.'</a></li>'."\n";
}
}
# Call crtLinks() function and display the links on the page:
crt_links("Home");
crt_links("About");
crt_links("Work");
crt_links("Resume");
crt_links("Code");
crt_links("Contact");
crt_links("Forum");
crt_links("Guestbook");
crt_links("Links");
crt_links("Dotcoms"); // Add links here to reflect abave link/title list.
?>
</ul>
</div>The above script works great if the URL looks like this:
Code: Select all
http://www.myDomain.com/folio/index.php?display=workCode: Select all
http://www.myDomain.com/folio/index.php?display=work&test=3d_study&img=1I need help.... how can I make my code ignore everything in the URL starting with "&" on up? Or, can anyone suggest a better way to compare the array elements to URL?
Hopefully that makes sense... Also, any feedback on the code would be appreciated... Is there a way I could make my script more compact/execute faster?
Thanks a billion in advance all!
Cheers
Micky