View Full Version : Breadcrumb hell

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.


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.

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...
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".

$path = $_SERVER["PHP_SELF"];
$parts = explode('/',$path);
if (count($parts) < 2)
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> ->");
$str = $parts[$i];
$pos = strrpos($str,".");
$parts[$i] = substr($str, 0, $pos);
echo $parts[$i];

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> ->

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?

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.


$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


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...

02-04-2007, 07:31 PM

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


uppercase the first letter of a string.


GJay ... you beat me to it!

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