Jump to content

breadcrumb problems


brooksh

Recommended Posts

This script works fine except, the a href only displays baseurl/current_folder instead of baseurl/other_folder/other_folder/current_folder

 

I'm sure it's simple, but I can't figure it out.

 

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("<p><a href=\"$base_url\">$home</a></p>");

    $last = end(array_keys($path));

    foreach ($path AS $x => $crumb) {
        $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb));
        $title = ucwords(str_replace(array('.html', '_'), Array('', ' '), $crumb));
        if ($x != $last){
            $breadcrumbs[] = "<p><a href=\"$base_url$crumb\">$title</a></p>";
        }else{
            $breadcrumbs[] = "<p>$title</p>";
	}
    }

    return implode($separator, $breadcrumbs);
}	

echo breadcrumbs();

Link to comment
https://forums.phpfreaks.com/topic/250570-breadcrumb-problems/
Share on other sites

Oh Well, just changed the script

 

function breadcrumbs(){
    $bread = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
    $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
  $url = '/';
  $returnString = "<span class='bc0'><p><a href='$url'>home</a></p>";
  for($i=1;$i<count($bread)-1;$i++){
    $url.=$bread[$i].'/';
    $returnString .= "</span> <span class='bc$i'><p><a href='$url'>$bread[$i]</a></p>";
  }
  echo $returnString.'</span>';
}

breadcrumbs();

Link to comment
https://forums.phpfreaks.com/topic/250570-breadcrumb-problems/#findComment-1285716
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.