I have a great bread crumb script but am having problems adding additionally needed functionality.
I need to add 2 conditions:
#1).
If the file name is not given in my bread crumb name translation file
("test.html" => "Test Page") then parse the name as it is given before the period, and capitalize the first letter;
therefore "test.html" => "Test"
#2).
If the file is index.html, then print trail just as if the url ended in a directory.
Currently:
www.mysite.com/Test/ gives me
Test (desired)
www.mysite.com/Test/index.html gives me
Test > index.html (not desired)
Trying for:
www.mysite.com/Test/index.html gives me
Any help is greatly appreciated!!! Code is below:
<?
// The following code produces the breadcrumb
// trail visible in the secondary and tretiary navigation
// last updated jf 4-18-02
include ("programs/bread_dir_names.php");
// Call the array that holds the custom directory names for the breadcrumbs
$urlstring = getenv('REQUEST_URI');
// on "http://boaz.hartnell.cc.ca.us/test/index.html" REQUEST_URI "returns /test/index.html"
$urlstring = preg_replace("/\/|\/$/", "", $urlstring);
// replaces first forward slash with blank, takes "/test/index.html" returns "test/index.html"
$crumbs = preg_split("/\//", $urlstring);
$j = sizeof($crumbs);
//j now equals the # of crumbs (/test/testlevel2/index.html = 3 where /test/testlevel2/ = 2
echo " > <a href=\"http://www.yoursite.com/index.html\">Home</a>";
// hard code the Index page
if ($urlstring != "")
{
for ($i=0; $i<$j; $i++)
{
$crumb = $crumbs[$i];
if (($crumbname = $breadcrumb[$crumb]) == "")
$crumbname = $crumb;
if ($i == $j-0)
{
/ Current Page /
// echo " > <b>$pagetitle</b>";
}
else
{
//echo "current crumb: ".$crumb."<br>";
preg_match("/.+\b$crumb\b\/?/", getenv('REQUEST_URI'), $thisurl);
// added boundary elements to original code
//echo "current url: ".$thisurl[0]."<br>";
echo " > <a href=\"$thisurl[0]\">", $crumbname, "</a>";
}
}
}
?>
Thanks!
James