Zend - The PHP Company




HTML

Add Code


header / sidebar / footer link level determiner  

Type: application
Added by: jasendorf
Entered: 23/05/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 7369
I made this bit of code (with a lot of help from the list serv people, THANKS!) and thought I would share it. This is my first post, so please be gentle. This code is designed to be required on every web page in the web site. It should automatically pick up the depth of a page in the file directory and then assign the proper link to a directory FROM THE ROOT. The first part of this script finds how deep the page is from the root. The second part is an array of all of the links you want listed. The third part sorts and lists the links. You should then be able to require this script on any page in your website and all of the links will work. I hope to make the next version of this determine if a link is in the directory currently accessed. (any help? wink wink) If this helps anyone, please let me know. jasendorf@lcounty.com John Asendorf


<?PHP

//establish page level and assign it $levels

/* The next line has been a pain
in my rear... you may need to play with it to
make it work on your particular system.  I've
tried to include some of the things that
have worked for me */

//for Apache on Win, uncomment next line
//$URL_vars=explode("/",$REQUEST_URI);
//for IIS as ISAPI module on Win, uncomment next line
//$URL_vars=explode("/",$URL);
//for IIS as CGI on Win, uncomment next line
//$URL_vars=explode("\\",$PATH_TRANSLATED);


$URL_parts=sizeof($URL_vars);

/*IMPORTANT You may need to change the number below depending on the real depth of your root directory*/
$URL_parts=$URL_parts-2;

$levels="";
$i=1;
if(
$i<$URL_parts) {
    while(
$i $URL_parts) {
        
$levels.="../";
        
$i++;
    }
}

//array for global web site links
//pairs are: directory => department name
//CASE SENSATIVE - upper case proceeds lower case 

$arr_links = array('dept1/' => 'Department 1',
           
'dept5/' => 'Department 5',
           
'dept6/' => 'Department 6',
           
'dept4/' => 'Department 4',
           
'dept2/' => 'Department 2',
           
'dept3/' => 'Department 6');
           
//alphabetize array by department name

asort($arr_links);

//make the list of links
//the '/' in the break tag is an XHTML convention

while ( list($key$val) = each($arr_links) ) {
            echo 
"<A href="$levels$key">$val</A><br />n";
}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories