Hello, I am having trouble designing a navigational bar that will work on all pages of my site. I wanted to use <?php include("navigationbarname.extension")?> on my index page in root directory, where the navigation bar was something like this: <ul class="navbar"> <li><a href="." class="nav">Home</a></li> <li><a href="typesofsteak/" class="nav">Types of Steak</a></li> <li><a href="steakpreparation/" class="nav">Preparation</a></li> <li><a href="steakhouses/" class="nav">Steakhouses</a></li> </ul> However, I cannot include that same file on the other pages of the site because the relative links will be better. Right now I am using absolute links. Is there a way I could code my navigation bar so it can be included in different subdectories using relative links? Thanks, Daniel
there shouldn't be a problem with that at all....but you do have some weird referencing with the href's. try using a .php extension for the file name. I do it on a few of my sites and it works without a hitch....
hmm, those links are to folders, like a href="typesofsteak/" points to domain.com/typesofsteak/index.php , but the users cannot tell it is a php page. If I only used the navigation bar on my domain.com/index.php page, I would not have an issue, but I want to also include the same navigation bar on the other pages of my site, such as /typesofsteak/index.php, but I can't simply include ../navigationbar.html because the relative links would no longer work.
<? // Root domain path, - trailing slash $root_dom = "http://yourdomain.com"; // incase u ignore the - trailing slash bit $root_dom = preg_replace("@/$@", "", $root_dom); ?> <ul class="navbar"> <li><a href="<?=$root_dir ?>" class="nav">Home</a></li> <li><a href="<?=root_dir ?>/typesofsteak/" class="nav">Types of Steak</a></li> <li><a href="<?=root_dir ?>/steakpreparation/" class="nav">Preparation</a></li> <li><a href="<?=root_dir ?>/steakhouses/" class="nav">Steakhouses</a></li> </ul> PHP: That'll work ....
Thanks very much for the code. I changed <li><a href="<?=$root_dir ?>" class="nav">Home</a></li> to <li><a href="<?=$root_dir ?>/" class="nav">Home</a></li>, and added a $ in front of the other root_dirs and it worked great. Just curious, is it faster to use the PHP code or absolute links if a domain has many visitors? Edit: hmm I think the php processor on my web host is very slow
very little overhead if any, and oops sorry for leaving out characters, in the middle of the day aswell ....