bshirey44 Posted December 28, 2012 Share Posted December 28, 2012 I was attempting to add a crumb trail to my site that is being modeled after the second example from the book. I am new to web development and php. I found lots of examples of php crumb trails on google, but they don't quite work well with this site. I was wondering if anyone has added this functionality to a site based on the second example and if so would you mind sharing? Thanks. Link to comment Share on other sites More sharing options...
Larry Posted December 29, 2012 Share Posted December 29, 2012 I've not seen anyone else discuss this yet, but it's worth doing. Link to comment Share on other sites More sharing options...
bshirey44 Posted December 29, 2012 Author Share Posted December 29, 2012 Larry once I get back to my office I'll post the php function I've been trying to modify and maybe you can point me in the right direction. It doesn't quite work because of how you hide the file names from the url. It's probaby an easy fix but I've been spinning my wheels. Thanks. Link to comment Share on other sites More sharing options...
bshirey44 Posted January 2, 2013 Author Share Posted January 2, 2013 <?php // This function will take $_SERVER['REQUEST_URI'] and build a breadcrumb based on the users current path function breadcrumbs($separator = ' » ', $home = 'Home') { // This gets the REQUEST_URI (/path/to/file.php), splits the string (using '/') into an array, and then filters out any empty values $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); // This will build our "base URL" ... Also accounts for HTTPS $base = 'http' . '://' . $_SERVER['HTTP_HOST'] . '/'; // Initialize a temporary array with our breadcrumbs. (starting with our home page, which I'm assuming will be the base URL) $breadcrumbs = Array("<a href=\"$base\">$home</a>"); // Find out the index for the last value in our path array $keys = array_keys($path); $last = end($keys); // Build the rest of the breadcrumbs foreach ($path AS $x => $crumb) { // Our "title" is the text that will be displayed (strip out .php and turn '_' into a space) $title = ucwords(str_replace(Array('.php', '_'), Array('', ' '), $crumb)); // If we are not on the last index, then display an <a> tag if ($x != $last) $breadcrumbs[] = "<a href=\"$base$crumb\">$title</a>"; // Otherwise, just display the title (minus) else $breadcrumbs[] = $title; } // Build our temporary array (pieces of bread) into one big string return implode($separator, $breadcrumbs); } Link to comment Share on other sites More sharing options...
Larry Posted January 2, 2013 Share Posted January 2, 2013 Thanks for sharing that. I assume it's working for you as you wanted? Link to comment Share on other sites More sharing options...
Recommended Posts