Log in

View Full Version : Dynamic site navigation



jvbates@mac.com
04-11-2006, 11:10 PM
Hope someone can help me out with something - I'm a HTML/CSS developer who know's a little PHP, which I use to make smaller sites semi-dynamic, I want to expand on what i'm currently doing but need some help.

I currently use PHP to create a single included .php file that contains the navigation, that knows via a variable hard-coded in the XHTML page, what section that page is from and them marks the navigation <li> with a class the highlights it.

Here's the code I currently use

XHTML page



<?php
//Section identifier - numbered or named'
$Section="section1"
?>


Included navigation.php file



<li<?php if ($Section=="section1") echo " class=\"selected\""; ?>><a href="#" title="">Home</a></li>


So (eventually) I get to my question... Rather than having a variable written into the top of each page, could I create a globals.php file that's included from everypage that knows what section that page is is from it's parent folder.

So if I hard-coded the folders/variables in this page, then the page recognises which folder it's from and applys that variable to the navigation.php

Any help much appreciated

Jay