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
Share on other sites

There aren't any errors in the script that I see, just I don't know how to get the href to display.

 

For Example: Home > Page1 > Subdirectory1 > Link

 

Right now the href is www.mydomain.com/link

 

when it should be

 

www.mydomain.com/page1/subdirectory1/link

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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