Zend - The PHP Company




Menus & Navigation

Add Code


Breadcrumbs navigation  

Type: code fragment
Added by: reywob
Entered: 07/01/2001
Last modified: 31/10/2000
Rating: - (fewer than 3 votes)
Views: 25834
This code will produce a useful navigation resource, showing visitors where they are in your site. Version 1.01 Fixed bug which printed wrong URL for more than one directory deep paths. Version 1.02 Removed some legacy code from the original implementation at users.f2s.com


<?php
/*
 * Breadcrumbs, version 1.02
 * This code is copyright (c) Peter Bowyer, and is released 
 * under the lesser general public license (LGPL). Please leave this 
 * notice intact!
 * This code was originally written for the F2S unofficial 
 * support site <http://www.users.f2s.com>
 * 
 * If you modify the code, please let me know.  I am always
 * after improvements! Contact me at <peter@mapledesign.co.uk>
 * 
 */

// If your server doesn't support $HTTP_HOST variable, uncomment the lower
// variable, and enter your site name.  Do not remove the trailing slash!
$site "http://".$HTTP_HOST."/";
// $site = "http://www.yoursite.com/";


//  If you are on a windows machine you may have to alter this line.
$str $PHP_SELF;

ereg("^(.+)/.+\..+$"$str$part);
$str $part[1];
$str substr($str1);

// Define the names you want given to each of the directories
// e.g. directory test has the label Test which will be visible
$label =  array("test"=>"Test",
                
"faq"=>"FAQ/Tutorials",
                
"phorum"=>"Forums",
                
"links"=>"Links",
                
"asp2php"=>"ASP2PHP",
                
"whatsnew"=>"What's New",
                
"us"=>"Useful Stuff");

if (
ereg("/"$str)){
$arr split("/"$str);
$num count($arr);
    for(
$i=0$i $num; ++$i){
    echo(
" > <a href="". $site . $arr[$i] ."/">".$label[$arr[$i]]."</a>");
    
$site $site $arr[$i] ."/";
    }
}elseif (
ereg("[a-zA-Z_]{1,}$",$str)){
$arr $str;
echo(
" > <a href="http://".$HTTP_HOST."/".$arr."/">".$label[$arr]."</a>");
}else{
echo(
"");
}

?>


Usage Example


<a href="http://www.users.f2s.com">Home</a>  > <a href="http://www.users.f2s.com/whatsnew">What's New</a>


Rate This Script





Search



This Category All Categories