Return to Snippet

Revision: 5073
at November 7, 2008 22:19 by localhorst


Updated Code
<?php

function mybreadcrumb ($start_id, &$struct_array, $end_id, $spacer=' &gt; ') {
	//builds the breadcrumb menu based on given values
	//$link_to = the page on which the breadcrum part links
	//$root_name = name of the breadcrumb part if empty/false/0 $start_id
	//$spacer = how should breadcrumb parts be divided

	$start_id 	= intval($start_id);
	$end_id 	= intval($end_id);
	$act_id 	= $start_id; //store actual ID for later comparing
	$breadcrumb = '';

	while ($start_id) { //get the breadcrumb path starting with given start_id
		if($end_id && $start_id == $end_id ) break;
		$data[$start_id] = $struct_array[$start_id]["acat_name"];
		$start_id		 = $struct_array[$start_id]["acat_struct"];
		
	}
	$data[$start_id] = $struct_array[$start_id]["acat_name"];
	$crumbs_part = array_reverse($data, 1);
	//print_r($crumbs_part);
	if(is_array($crumbs_part)) {
	$i=1;
		foreach($crumbs_part as $key => $value) {
			$alias = '';
			$active = ($i == count($crumbs_part)-1)? "pre_active" : "";
			$active .= ($i == count($crumbs_part))? "active" : "";
			if($struct_array[$key]["acat_hidden"] != 1) { // check if the structure should be unvisible when active
				if ($act_id != end_id) {
					if($breadcrumb) $breadcrumb .= $spacer;
					if(!$struct_array[$key]["acat_redirect"]) {
						$breadcrumb .= '<a class="breadcrumb_level_'.$i.' '.$active.'" href="index.php?';
						$alias 		 = $struct_array[$key]["acat_alias"];
						$breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key.',0,0,1,0,0';
						$breadcrumb .= '">';
					} else {
						$redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
						$breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
					}
					$breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
				} else {
					if($breadcrumb) $breadcrumb .= $spacer;
					$breadcrumb .= html_specialchars($crumbs_part[$key]);
				}
				$i++;
			}
		}
	}
	return $breadcrumb;
}



//breadcrumb replacement
if(strpos($content["all"],'{MYBREADCRUMB') !== false) {
	$content["all"] = str_replace('{MYBREADCRUMB}', '{MYBREADCRUMB:0}', $content["all"]);
	$replace = '@mybreadcrumb($GLOBALS["content"]["cat_id"], $GLOBALS["content"]["struct"], $1, $template_default["breadcrumb_spacer"]);';
	$content["all"] = preg_replace('/\{MYBREADCRUMB:(\d+)\}/e', $replace, $content["all"]);
}
?>

Revision: 5072
at February 9, 2008 00:49 by localhorst


Initial Code
<?php

function mybreadcrumb ($start_id, &$struct_array, $end_id, $spacer=' &gt; ') {
	//builds the breadcrumb menu based on given values
	//$link_to = the page on which the breadcrum part links
	//$root_name = name of the breadcrumb part if empty/false/0 $start_id
	//$spacer = how should breadcrumb parts be divided

	$start_id 	= intval($start_id);
	$end_id 	= intval($end_id);
	$act_id 	= $start_id; //store actual ID for later comparing
	$breadcrumb = '';

	while ($start_id) { //get the breadcrumb path starting with given start_id
		if($end_id && $start_id == $end_id ) break;
		$data[$start_id] = $struct_array[$start_id]["acat_name"];
		$start_id		 = $struct_array[$start_id]["acat_struct"];
		
	}
	$data[$start_id] = $struct_array[$start_id]["acat_name"];
	$crumbs_part = array_reverse($data, 1);
	//print_r($crumbs_part);
	if(is_array($crumbs_part)) {
	$i=1;
		foreach($crumbs_part as $key => $value) {
			$alias = '';
			$active = ($i == count($crumbs_part)-1)? "pre_active" : "";
			$active .= ($i == count($crumbs_part))? "active" : "";
			if($struct_array[$key]["acat_hidden"] != 1) { // check if the structure should be unvisible when active
				if ($act_id != end_id) {
					if($breadcrumb) $breadcrumb .= $spacer;
					if(!$struct_array[$key]["acat_redirect"]) {
						$breadcrumb .= '<a class="breadcrumb_level_'.$i.' '.$active.'" href="index.php?';
						$alias 		 = $struct_array[$key]["acat_alias"];
						$breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key.',0,0,1,0,0';
						$breadcrumb .= '">';
					} else {
						$redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
						$breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
					}
					$breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
				} else {
					if($breadcrumb) $breadcrumb .= $spacer;
					$breadcrumb .= html_specialchars($crumbs_part[$key]);
				}
				$i++;
			}
		}
	}
	return $breadcrumb;
}



//breadcrumb replacement
if(strpos($content["all"],'{MYBREADCRUMB') !== false) {
	$content["all"] = str_replace('{MYBREADCRUMB}', '{BREADCRUMB:0}', $content["all"]);
	$replace = '@mybreadcrumb($GLOBALS["content"]["cat_id"], $GLOBALS["content"]["struct"], $1, $template_default["breadcrumb_spacer"]);';
	$content["all"] = preg_replace('/\{MYBREADCRUMB:(\d+)\}/e', $replace, $content["all"]);
}
?>

Initial URL

                                

Initial Description
customized breadcrumbnavigation for PHPWCMS.
Gives more control over styling and display.
{MYBREADCRUMB:n}

Initial Title
Extended Breadcrumbnavigation

Initial Tags
navigation

Initial Language
PHP