4
Howdie all!
I was looking for a way to display breadcrumbs in the old phpwiki XOOPS module. I had already done a
pagetitle hack and I thought it would be interesting to reuse this information in a breadcrumb.
I was looking for a quick solution using php and cookies and I quickly stumbled on this
solution for history breadcrumbs.
This is what I did in phpwiki:
Make a breadcrumbs.php file in the module root with this content
/*
Copyright Justin Whitford 2006.
http://www.whitford.id.au/
Perpetual, non-exclusive license to use this code is granted
on the condition that this notice is left in tact.
*/
$trailLength=5;
$staleCrumbList = explode('|',$_COOKIE['breadcrumbs']);
if (
$_SERVER['REQUEST_URI'].'!'.$pageName !=
$staleCrumbList[count($staleCrumbList)-1]
){
$crumbList;
$startPoint=(count($staleCrumbList) < $trailLength+1)?0:1;
for($i=$startPoint;$i<count($staleCrumbList);$i++){
$crumbList[$i]=$staleCrumbList[$i];
}
$crumbList[count($crumbList)+1]=$_SERVER['REQUEST_URI'].'!'.$pageName;
setcookie('breadcrumbs',join('|',$crumbList),0,'/');
$_COOKIE['breadcrumbs']=join('|',$crumbList);
}
function breadcrumbs(){
$crumbList = explode('|',$_COOKIE['breadcrumbs']);
$returnString = '';
for($i=1;$i<count($crumbList)-1;$i++){
$crumb=explode('!', $crumbList[$i]);
$returnString .= "$i' class='crumb'>"
."$crumb[0]'>$crumb[1] → ";
}
$crumb=explode('!', $crumbList[count($crumbList)-1]);
echo $returnString.$crumb[1];
}
?>
Add this code in html.tmpl before printf
if($_SERVER['REQUEST_URI'] == '/modules/phpwiki/' || $_SERVER['REQUEST_URI'] == '/modules/phpwiki/index.php'){
$pageName = 'Bestuur';}
else {
$pageName = preg_replace('(/modules/phpwiki/index.php?pagename=(.*))', '$1', $_SERVER['REQUEST_URI']);
$pageName = ucfirst(ereg_replace('%20', ' ', $pageName));}
include ($_SERVER['DOCUMENT_ROOT'] . '/modules/phpwiki/breadcrumbs.php');
Add this code in top.tmpl under = $HEADER ?>
(); ?>
You can see the result on the
Stad Sint-Niklaas website.
I'm posting this here because this solution may be useful to module developers that use intuitive SEO url's.