Click to See Complete Forum and Search --> : breadcrumb code


chris9902
02-03-2004, 05:25 AM
when displaying this script it shows a breadcrumb but it also displays the page name you are on.

how do i make it not display the page i am on only everything before it like on www.macromedia.com

<?
$def = "index"; //default web page for directories on your server.
$dPath = $PHP_SELF; //Get the script path, relative to web root.
$dChunks = explode("/", $dPath); //Separate out folder and file names by looking for slashes.
?>
<a class="dynNav" href="/">Home</a><span class="dynNav"> / </span>
<!-- make a leading "home" link -->
<?

for($i=1; $i<count($dChunks); $i++){ //PHP arrays are 0 inxeded but we are skipping the first element
//because of the way explode() works.
echo("<a class=\"dynNav\" href=\"/"); //Make each chunk a link.
for($j=1; $j<=$i; $j++){ //Subloop to create the path for each chunk.
echo($dChunks[$j]); //Write each piece of the chunk's path.
if($j!=count($dChunks)-1) echo("/");//If that piece was a folder name, append a slash.
}
if($i==count($dChunks)-1){ //If the chunk is a file, not folder name...
$prChunks = explode(".", $dChunks[$i]); //take out the file extension...
if ($prChunks[0] == $def) $prChunks[0] = ""; //don't display the filename
if it's index or whatever default you specified.

$prChunks[0] = $prChunks[0] . "</a>"; //add the closing tag.

}
else $prChunks[0]=$dChunks[$i] . "</a><span class=\"dynNav\"> / </span>";
//Otherwise, just use the chunk name, close the a tag and add a paddeslash for disply.
echo('\"\>');ay. echo('\"\>');
echo(str_replace("_" , " " , $prChunks[0])); //Finish writing the link, replacing underscores with spaces for the end user.
}
?>

PunkSktBrdr01
02-03-2004, 06:43 PM
Replace this:


for($i=1; $i<count($dChunks); $i++){


with this:


for($i=1; $i<count($dChunks) - 1; $i++){


and replace this:


if($i==count($dChunks)-1){
$prChunks = explode(".", $dChunks[$i]);
if ($prChunks[0] == $def) $prChunks[0] = "";
$prChunks[0] = $prChunks[0] . "</a>";

}
else $prChunks[0]=$dChunks[$i] . "</a><span class=\"dynNav\"> / </span>";
echo('">');
echo('\">');
echo(str_replace("_" , " " , $prChunks[0]));
}


with this:


$prChunks[0]=$dChunks[$i] . "</a><span class=\"dynNav\"> / </span>";
echo('">');
echo('\">');
echo(str_replace("_" , " " , $prChunks[0]));

chris9902
02-04-2004, 05:15 AM
thank you.

it now looks like this and work great

<?php
$def = "index"; //default web page for directories on your server.
$dPath = $PHP_SELF; //Get the script path, relative to web root.
$dChunks = explode("/", $dPath); //Separate out folder and file names by looking for slashes.
?>
<a class="dynNav" href="/">Home</a><span class="dynNav"> / </span>
<!-- make a leading "home" link -->
<?php
for($i=1; $i<count($dChunks) - 1; $i++){ //PHP arrays are 0 inxeded but we are skipping the first element
//because of the way explode() works.
echo("<a class=\"dynNav\" href=\"/"); //Make each chunk a link.
for($j=1; $j<=$i; $j++){ //Subloop to create the path for each chunk.
echo($dChunks[$j]); //Write each piece of the chunk's path.
if($j!=count($dChunks)-1) echo("/");//If that piece was a folder name, append a slash.
}
$prChunks[0]=$dChunks[$i] . "</a><span class=\"dynNav\"> / </span>";
echo('">');
echo(str_replace("_" , " " , $prChunks[0]));
}
?>

chris9902
02-04-2004, 05:17 AM
one more thing.

is there a way to display the page i am on but not as a link.

so you have link / link / link / page

PunkSktBrdr01
02-04-2004, 07:26 PM
That'll require an entire rewrite of the script. I'll try to post it later tonight. :)

PunkSktBrdr01
02-04-2004, 10:19 PM
Okay, I figured it out. Here it is:


<html>
<head>
<title>Bread Crumb Test Page</title>
</head>
<body>
<div id="breadcrumb">
<a href="/">Home</a>/
<?php
$crumbs = explode("/", $_SERVER['PHP_SELF']);
for ($i = 1; $i < count($crumbs); $i++) {
$link = "";
if ($i == (count($crumbs) - 1)) {
$link = explode(".", $crumbs[$i]);
$link = $link[0];
echo "<span style=\"font-weight: bold;\">" . $link . "</span>\n";
}
else {
for ($ii = 0; $ii <= $i; $ii++) {
$link .= $crumbs[$ii] . "/";
}
echo "<a href=\"" . $link . "\" class=\"dynNav\">" . $crumbs[$i] . "</a>/\n";
}
}
?>
</div>
</body>
</html>


Let me know how it works! :)

chris9902
02-05-2004, 03:07 AM
PERFECT!

thank you so much...

PunkSktBrdr01
02-05-2004, 07:04 AM
Glad to help. :)