...

View Full Version : Breadcrumb hell



buildrebuild
02-04-2007, 04:54 PM
Hi all,
I've downloaded short of 30 PHP Breadcrumb scripts and none of them work properly. I know enough PHP to set them up properly, it's just that they don't do what I want. Usually the last link in the list of beadcrumbs is clickable which is pointless as it will link to the same page.
Even here in the forums I've done a search and there is very little info.

Anyone out there got a good PHP breadcrumb script, and if you wouldn't mind sharing it, please post it up?

A big issue is the suffix on the end of links in the location bar. I would like to hide the .php suffix.

Thanks
Cb

koyama
02-04-2007, 05:42 PM
I don't know what such a breadcrumb script looks like. On the other hand it is probably possible to modify it to get what you want.

Perhaps you'll get better response if you show us what you have so far.

buildrebuild
02-04-2007, 06:15 PM
I have this but there is a problem with the way it reads my folder structure.
I have and index page in each of my folders...
index.php
about(Folder) - index.php
portfolio(Folder) - index.php
contact(Folder) - index.php

When I link to other files within, lets say, the porfolio folder there will be a link back to the porfolio folder+"index". I would want there just to be a link back to "portfolio".

<?php
$path = $_SERVER["PHP_SELF"];
$parts = explode('/',$path);
if (count($parts) < 2)
{
echo("home");
}
else
{
echo ("<a href=\"/index.php\">home</a> -> ");
for ($i = 1; $i < count($parts); $i++)
{
if (!strstr($parts[$i],"."))
{
echo("<a href=\"");
for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";};
echo("\">".$parts[$i]."</a> ->");
}
else
{
$str = $parts[$i];
$pos = strrpos($str,".");
$parts[$i] = substr($str, 0, $pos);
echo $parts[$i];
};
};
};
?>

koyama
02-04-2007, 06:47 PM
I must be missing something. When you are viewing

Portfolio (folder) - somepage.php

You get generated this breadcrumb, right?

<a href="/index.php">home</a> ->
<a href="/portfolio/">portfolio</a> ->
->somepage

Now when you click on portfolio in the bread crumb it will take you to /portfolio/ and you will get to see the page /porfolio/index.php.

Explain what is wrong here, and how would you like it to be instead?

buildrebuild
02-04-2007, 07:16 PM
Hi, thanks for the help.
Got this script which works a treat. Now all I need is for the first letter of each breadcrumb to be converted to a capital.


<?php

$path = $_SERVER["PHP_SELF"];
$tree = split("/",$path);
$breadcrumb = "";
if (count($tree)==2 && $tree[1]=="index.php") { // First, check if we are on the home page
$breadcrumb = "home";
} else { // If not, then first put a link to the homepage
$breadcrumb = "<a href=\"/index.php\">home</a>";
for ($i=1; $i<count($tree); $i++) { // Now step through each level adding a link, until we reach an actual file
if (strstr($tree[$i],".")) { // Found a file (i.e. it has a fullstop character in it)
if ($tree[$i]!="index.php") { // If it is not the index page of the current folder, print the name
$pagename = split("\.",$tree[$i]);
$breadcrumb = $breadcrumb . " &gt; " . str_replace("_"," ",$pagename[0]);
}
} else { // Found another directory, so provide a link to the top level...
if ($tree[$i+1]=="index.php") { // ...unless the next one down is the index page
$breadcrumb = $breadcrumb . " &gt; " . str_replace("_"," ",$tree[$i]);
} else {
$breadcrumb = $breadcrumb . " &gt; <a href=\""; // Add the arrow between nodes
for ($j=1; $j<=$i; $j++) { // Add the right link depth to the actual link
$breadcrumb = $breadcrumb . "/" . $tree[$j];
}
$breadcrumb = $breadcrumb . "/\">" . $tree[$i] . "</a>";
}
}
}
}
echo $breadcrumb; // Print the final breadcrumb trail to the page
?>


Best,
CB

rizwan
02-04-2007, 07:31 PM
automate only work when you have structured page system. mean if the link is page1 and dir name dir1 and it will print some thing page1 and there is no use of it.

I think its better for you to develop your own which will suite what you want..... instead of wasting time on searching and testing...

GJay
02-04-2007, 07:31 PM
http://php.net/ucwords

mlseim
02-04-2007, 10:44 PM
use "ucwords" ...

http://us3.php.net/ucwords

uppercase the first letter of a string.

$breadcrumb=ucwords($breadcrumb;

EDIT:
GJay ... you beat me to it!

marek_mar
02-04-2007, 11:01 PM
He was only 3 hours faster. :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum