Picnic Website Code Tutorials

How To Breadcrumb Navigation

6/17/2013

View Demo

This 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> &raquo; ");
	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]);
        	};
    	};
	};  
?>
		

Sponsors

Top Donators

Friends of Mine