Setting up a breadcrumb
Posted: Thu May 31, 2007 6:33 am
I'm trying to add a breadcrumb nav to an existing site, but I'm finding it a bit harder going than I had expected.
Mostly, the page flow runs: Home > Search Result > Brand > Customise or > Order
My issue in this regard is that you can also get to brand from the Brand Listing page. So what if someone bookmarks a brand (I set it up so they can and should if they like) .... what back branch should be set?
From Home, Login or Sign Up are also options, and then there is Admin and all the branches under that.
I've tried to set it up dynamically, but I cant figure dynamic backbuilding for pages accessed directly, and I also cant figure out how to avoid issues with people manually jumping steps. For example, getting to the Brand page and then using the address bar to get into one of the admin pages. The dynamic method I came up with just adds itself onto the end of the existing trail.
Heres what I had tried.
Mostly, the page flow runs: Home > Search Result > Brand > Customise or > Order
My issue in this regard is that you can also get to brand from the Brand Listing page. So what if someone bookmarks a brand (I set it up so they can and should if they like) .... what back branch should be set?
From Home, Login or Sign Up are also options, and then there is Admin and all the branches under that.
I've tried to set it up dynamically, but I cant figure dynamic backbuilding for pages accessed directly, and I also cant figure out how to avoid issues with people manually jumping steps. For example, getting to the Brand page and then using the address bar to get into one of the admin pages. The dynamic method I came up with just adds itself onto the end of the existing trail.
Heres what I had tried.
Code: Select all
function getBreadCrumb($current_name, $current_link) {
if(!isset($_SESSION['BC_NAV'])) $_SESSION['BC_NAV']['Home'] = "index.php";
if(!in_array("index.php", $_SESSION['BC_NAV'])) {
// Add element to the end of the breadcrumb array
$_SESSION['BC_NAV'][$current_name] = $current_link;
} else {
$found = false;
foreach($_SESSION['BC_NAV'] as $name=>$link) {
if($found) unset($_SESSION['BC_NAV'][$name]);
if($name==$current_name) $found = true;
}
}
// Construct final breadcrumb trail
$final_element = end($_SESSION['BC_NAV']);
foreach($_SESSION['BC_NAV'] as $name=>$link) {
if($link==$final_element)
$new_bc[] = "<em>$name</em>";
else
$new_bc[] = "<a href=\"$link\">$name</a>";
}
return "<strong>You are here: </strong>" . implode(" > ", $new_bc);
}