New Screencast: Current Nav Highlighting - Using PHP to Set the Body ID
* September 18th, 2008 *
One of the more efficient ways to handle current navigation highlighting is to give each of your navigation items a unique class name. Then give each page a unique ID on the body element. Then CSS can control what each navigation item looks like based on that body ID. But what if you are using a CMS like WordPress which includes that body tag as part of a template? In this case, we can use PHP to look at the URI of the page and create the ID based on that. Nifty trick!
Long story short?
...
</head>
<?php
$page = $_SERVER['REQUEST_URI'];
$page = str_replace("/","",$page);
$page = str_replace(".php","",$page);
$page = str_replace("?s=","",$page);
$page = $page ? $page : 'default'
?>
<body id="<?php echo $page ?>">





Nice Chris!
This is a neat little way to achieve such a goal. I remember reading about something similar to this once. Good explanation of it.
jordan