As per Drakla's ingenious <?php require_once(ROOT_OFFSET.'include/nav.php'); ?>, i have successfully setup my entire site page structure relatively easily, complete with global site navigation on EVERY page, AND w/ the confidence about my navigation component that "...if it works once, it works in every page...", i'm very pleased with my boost in progress, not to mention the ease with which i can now modify the navigation structure in only one file and have it affect the site globally!!
that's just too awesome!
it works because, where i would typically have my navcontainer coded into all of my pages, i simply remove the series of <a href="#">nav stuff</a> for all of the page links, and replace it with the code shown above-- thereby inserting an "include" file which takes care of all of that code for me-- it works because of Drakla's generous solution to my problem (that i created a site based on varying degress of sub-folders) which is based on placing the following code at the top of EVERY output page in my site structure:
<?php
require_once('xroot-offset.php');
?>
where a supplemental file accompanies the file containing the include, named xroot-offset.php, which contains an "offset" to account for the directory depth respective to that file which references it, for example define('ROOT_OFFSET', '../../');.
observe that placing this directory "offset" in the statement above require_once(ROOT_OFFSET.'include/nav.php') , the nav.php file is accurately located by the browser no matter what level of the hierarchy the current file resides-- assuming that xroot-offset.php is present, and the directory offset is accurate.
but here's the thing-- and this wouldn't necessarily be an issue for me, as i typically don't concern myself with whether or not my navigation indicates to the user his current page-view on the site (shame on me for that!), but this particular site has a deep navigation structure, with varying topical categories in which it is rather necessary to indicate current page-- as i'm not using breadcrumbs or any other such indicator.
one popular method for indicating "current page view", for the CSS enthusiast, is to style differently the "active" , "current" page anchor in the navmenu-- for example
<li><a href="index.php">Home</a></li>
<li><a href="page2.php">Page 2</a></li>
// CSS makes the next ITEM "stand out" in some way from the rest of the navLIST
<li id="active"><a href="page3.php" id="current">Page 3</a></li>
<li><a href="page4.php">Page 4</a></li>
why can i NOT use this technique? because by using the ROOT_OFFSET method, every browser output file (for all intents and purposes) references the very SAME navigation code-- therefore, i can NOT use this method to "highlight" the active, current page respective to the navigation.
but, i haven't given up on the CSS id="active" technique yet because-- for one thing, i can't think of any OTHER way to solve my "current page" problem-- and i have an idea that i might be able to use another file, in the spirit of xroot-offset.php which will somehow take care of the <li id="active"><a href="#" id="current">link</a></li>.
right now, i can't get my head around it enough to think what i might do in order to "insert" the CSS into only the current page's <a href> tag-- remember, that tag is in a singular file, in the includes folder, referenced into the page only by way of xroot-offset.php . can you think of how i might manipulate xroot-offset.php in each separate sub-folder so that the accomodation is made to place the CSS id's into the navigation code, affecting ONLY the "current" page?
EDIT: perhaps something like this, a sub-script to identify the location of the current page, added under the define statement in xroot-offset.php:
define('ROOT_OFFSET', '../../');
$folderdepth = dirname($path);
if ($folderdepth == "????") {
do something
} elseif ($folderpath != "????") {
don't do something
or do something else
}
any other ideas on how to approach this problem?
Thanks!!!