Breadcrumb generator function

Here is a piece of code i used for generating breadcrumbs for one of my project.

Function for generating breadcrumb

first parameter an array with key and values, value is used for link where as keys are used for link name.

second optional parameter for sending class of ul in the breadcrumb listing.

<?php
function breadcrumb_generate($paths = array(), $ul_class = 'breadcrumb')
{
	$forward_icon = '<img src="'.base_url().'images/front_img/icons/forward.png" alt="&raquo;" />';
    $breadcrumb = '<ul class="'.$ul_class.'">';
	$i=1;
	$total_paths = count($paths);
	foreach($paths as $path=>$link)
	{
		if($link!='nolink')
		{
			$breadcrumb .= '<li><span><a href="'.site_url($link).'">'.$path.'</a></span></li>';
		}
		else
		{
			$breadcrumb .= '<li><span>'.$path.'</span></li>';
		}
		$i++;
	}
	$breadcrumb .= '</ul>';

	return $breadcrumb;
}
?>

usage


<?php echo breadcrumb_generate(array('Home'=>'', 'Group'=>'group/browse', ucfirst($row->name)=>'group/'.$row->permalink, 'Forum'=>'group/'.$row->permalink.'/topic', $topic_row->title=>'nolink'), 'topicBreadcrumb');?>

css styles for listing breadcrumbs

ul.breadcrumb{
	padding-top:5px;
	width:400px;
}
ul.breadcrumb li{
	float:left;
	list-style:none;
	background:url(../images/front_img/icons/forward.png) no-repeat 0.2em 0;
	padding-left:17px;
}
ul.breadcrumb li span{
	padding:5px;
}
ul.breadcrumb li span:hover{
	padding:4px;
	border:1px solid #090;
	-moz-border-radius:5px; -webkit-border-radius:5px;

}
ul.breadcrumb li:first-child{
	background:none;
	padding-left:0px;
}

This is just a rough usage of this function. you can hack it up and use as needed.

This entry was posted in php. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>