Brenna of mngeo.com (and an all-around smart person on the MT boards!) posted really nice tutorial on how to make your site navigation know what page you are on; even when you are using a fixed header.
Brenna of mngeo.com (and an all-around smart person on the MT boards!) posted really nice tutorial on how to make your site navigation know what page you are on; even when you are using a fixed header.
2 | kristine
Yeah, I thought it looked familiar to something over here, but I didn't go looking like I should have! Thanks for posting the link
Still, like you said, its good to have options, and it was a well-written tutorial, so I wanted to share
3 | Jade
My way was slightly different. Here's my navigation file:
<?php
# set the info for the navi stuff. first part of each sub-array is the plain link, second is the active link.
$nav["about"] = array("<p><a href=\"/about\">about</a></p>", "<p class=\"active\"><a href=\"/about\">about</a></p>");
$nav["links"] = array("<p><a href=\"/links\">links</a></p>", "<p class=\"active\"><a href=\"/links\">links</a></p>");
$nav["weblog"] = array("<p><a href=\"/weblog\">weblog</a></p>", "<p class=\"active\"><a href=\"/weblog\">weblog</a></p>");
$nav["journal"] = array("<p><a href=\"/journal\">journal</a></p>", "<p class=\"active\"><a href=\"/journal\">journal</a></p>");
$nav["contact"] = array("<p><a href=\"/contact\">contact</a></p>", "<p class=\"active\"><a href=\"/contact\">contact</a></p>");
$nav["webcam"] = array("<p><a href=\"/webcam\">webcams</a></p>", "<p class=\"active\"><a href=\"/webcam\">webcams</a></p>");
$nav["phlog"] = array("<p><a href=\"/otw\">phlog</a></p>", "<p class=\"active\"><a href=\"/otw\">phlog</a></p>");
$nav["features"] = array("<p><a href=\"/features\">features</a></p>", "<p class=\"active\"><a href=\"/features\">features</a></p>");
$active = getenv(QUERY_STRING);
# for each $x in $nav check if $x is the same as the query string and if it is use $x[1] otherwise use $x[0]
foreach ($nav as $bit => $link) {
if ($bit == $active) {
print $link[1];
print "\n";
} else {
print $link[0];
print "\n";
}
}
?>
So with the comments in there you can pretty much understand what it does, even if you weren't familiar with PHP.
Then I include this in each of my pages like this:
<?php
include('http://www.whisper-gallery.com/shared/menu.php?links');
?>
or..
include('http://www.whisper-gallery.com/shared/menu.php?weblog');
Just have the bit after the question mark match the name of whatever element of $nav in the navigation script applies to the section of the site that you are wanting to mark as active.
You need to include the navigation script using the full URL because PHP does not provide any function for including local scripts with information being passed to them. And believe me, I looked 😉
Initially I was worried about having to use the full URL to include the script rather than just a local path, but the friend who hosts me said it was ok and wouldn't really use much more in the way of server resources because a properly configured server should recognise that it's requesting a page from itself rather than over the internet and skip a few steps in the whole thing process of serving the file to itself. Or something. Sorry, I'm not so great with web servers just yet 😉