How To Breadcrumb Navigation
6/17/2013This is how to make a breadcrumb navigation with PHP. It's very easy. Put the below code in an PHP include and simply place it where ever you want to show the breadcrumb navigation. Done! This is the same code I use on my site.
Breadcrumb PHP Code
<?php $path = $_SERVER["PHP_SELF"]; $parts = explode('/',$path); if (count($parts) < 2) { echo("home"); } else { echo ("<a href=\"/\">home</a> » "); for ($i = 1; $i < count($parts); $i++) { if (!strstr($parts[$i],".")) { echo("<a href=\""); for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";}; echo("\">". str_replace('-', ' ', $parts[$i])."</a> » "); } else { $str = $parts[$i]; $pos = strrpos($str,"."); $parts[$i] = substr($str, 0, $pos); echo str_replace('-', ' ', $parts[$i]); }; }; }; ?>