samoht Posted August 25, 2007 Share Posted August 25, 2007 Hello all, I have a remodeling site that has multiple services. Each service is in its own subfolder with an index.php. I have a leftnav bar that allows the user to navigate to each service - and I want to highlight the current service nav button. My problem is with the url. since the basename will always be index.php - how should I set the condition for the test of the url? Connected to this problem is - how do I code the path to the service so that it works on my local machine as well as when I upload the page (without having to manually change the path) Currently I have <?php $rpage = $_SERVER['SCRIPT_NAME']; $page = substr(($rpage),0,5); ?> <div id="ltnav"> <ul id="navleft"> <li<?php if($rpage== "/homestead/remodel/index.php"){echo " class=\"current\"";}?>> <a href="http://www.nextgenwt.com/homestead/remodel/">Remodel</a> </li> I don't want to put the full path in (at least not hard coded) Thanks for any help Quote Link to comment Share on other sites More sharing options...
pkSML Posted August 25, 2007 Share Posted August 25, 2007 <?php $rpage = $_SERVER['SCRIPT_NAME']; $page = substr(($rpage),0,5); ?> <div id="ltnav"> <ul id="navleft"> <li<?php if(stristr($rpage, 'remodel')){echo " class=\"current\"";}?>> <a href="http://www.nextgenwt.com/homestead/remodel/">Remodel</a> </li> Great way to merge PHP with CSS! BTW, you may not want to use dashed lines separating your columns. It gets muddy with IE6 when scrolling. Quote Link to comment Share on other sites More sharing options...
samoht Posted August 25, 2007 Author Share Posted August 25, 2007 Thanks! I'll consider different column seperation, maybe an img? Anyway, any ideas on how to get my <a href=""> to a relative path? Can I http://"<?php echo $_SERVER['ROOT'].$_SERVER['SCRIPT_NAME']."/realtivepath/";?> or something like this - but script_name will give me to much. Can I go back 1 file? ?? Quote Link to comment Share on other sites More sharing options...
pkSML Posted August 25, 2007 Share Posted August 25, 2007 You can just use a relative path. For example, if they're at the kitchens/index.php page, your link to remodeling would be <a href="../remodeling/index.php">. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 25, 2007 Share Posted August 25, 2007 If each one is in a folder, you don't need the index.php stuff, and it will look nicer. site.com/kitchens/ SHOULD work the same as site.com/kitchens/index.php Why don't you define your Site's BASE url as a constant: define('SITE_URL', 'http://site.com/'); and then whenever you have a link do: print '<a href="'.SITE_URL.'kitchens/">'; Quote Link to comment Share on other sites More sharing options...
samoht Posted August 25, 2007 Author Share Posted August 25, 2007 The problem is that the main page (something.com)'s index.php will also have the leftnav include so if I use a relative path of ../kitchens/ in leftnav.php - that wont work on the main page. I like the idea of defining a base url - but will that mean I hae to manually change that definition when I move the site from the local server to the live? Is there a function that can find my base url for me? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 25, 2007 Share Posted August 25, 2007 Yes, but it's ONE constant, as opposed to on every page. It will take two seconds to change. Quote Link to comment Share on other sites More sharing options...
pkSML Posted August 25, 2007 Share Posted August 25, 2007 The problem is that the main page (something.com)'s index.php will also have the leftnav include so if I use a relative path of ../kitchens/ in leftnav.php - that wont work on the main page. I like the idea of defining a base url - but will that mean I hae to manually change that definition when I move the site from the local server to the live? Is there a function that can find my base url for me? The answer is almost too easy... That is, if you have access to the $_SERVER['SERVER_NAME'] variable. At the beginning of your script, have this if statement. <?php if (stristr($_SERVER['SERVER_NAME'], "nextgenwt")) { // If we're on production server $path = "/homestead/"; } else { // If we're on localhost $path = "/"; // I don't know your localhost path, so you'll have to fill in this one } ?> Your links will look like this: <a href="<?php echo $path ?>remodel/">Remodel</a> This solution will work on both servers, and work on all the pages. Quote Link to comment Share on other sites More sharing options...
samoht Posted August 25, 2007 Author Share Posted August 25, 2007 Thanks Stephen - this is what I needed! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.