I have found this code online and it pretty much does what I would like it todo but there are just a few issues.
When I click on the home tab it adds https in front of the domain and it says this website is not available but if I remove the s it works.
also on the websites there are titles like home > aaa-bbb-ccc > aaa-bbb > aaa I will supply the old breadcrumb code we have and i'm wondering if we specify the url for the breadcrumbs.
Also when I view the website in the browser in the middle of the breadcrumb this appears Home > $title > index
Old Breadcrumbs:
<?php
/*
Copyright Justin Whitford 2006.
http://www.whitford.id.au/
Perpetual, non-exclusive license to use this code is granted
on the condition that this notice is left in tact.
*/
function breadcrumbs(){
$bread = explode('/', $_SERVER['PHP_SELF']);
$url = '/';
$returnString = "<span class='bc0'><a href='$url'>Home</a>";
for($i=1;$i<count($bread)-1;$i++){
$url.=$bread[$i].'/';
$returnString .= " ></span> <span class='bc$i'><a href='$url'>"
.prettify($bread[$i])."</a>";
}
echo $returnString.'</span>';
}
function prettify($dirName){
$directoryName['aaa-bbb-ccc']='Locate Us';
$directoryName['aaa-bbb']='Contact';
$directoryName['breadcrumbs']='Foe';
if($directoryName[$dirName]!=''){
$dirName=$directoryName[$dirName];
}else{
$dirName = str_replace('_', ' ', $dirName);
$dirName = str_replace('%20', ' ', $dirName);
$dirName = ucwords(strtolower($dirName));
}
return $dirName;
}
This is my new code:
<?php
function breadcrumbs($separator = ' > ', $home = 'Home') {
$path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
$base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
$breadcrumbs = array("<a href=\"$base_url\">$home</a>");
$last = end(array_keys($path));
foreach ($path AS $x => $crumb) {
$title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb));
if ($x != $last){
$breadcrumbs[] = '<a href="$base_url$crumb">$title</a>';
}else{
$breadcrumbs[] = $title;
}
}
return implode($separator, $breadcrumbs);
}
echo breadcrumbs();
?>
Thanks.