I wrote an extender which outputs a breadcrumbs navigation in Ditto.
Save the code below as "/assets/snippets/ditto/extenders/breadcrumbs.extender.inc.php" and include it in your ditto call with "&extenders=`breadcrumbs`".
Place a placeholder [+breadcrumbs+] in your custom template and you are done.
The breadcrumbs output itself can be completely customized with templates. See source code for more information.
I wrote this for myself, but maybe you find it useful...
Regards, Tensai
<?php
/*
* Title: Breadcrumbs
* Purpose:
* Legacy support for the [+breadcrumbs+] placeholder
*/
$placeholders['breadcrumbs'] = array("breadcrumbs","bcDetermineBreadcrumbs","");
$bcStartID = isset($bcStartID) ? $bcStartID : $parents;
/*
Param: bcStartID
Purpose:
ID of the start site for the breadcrumbs navigation.
If set to '0', the breadcrumbs naviagtion will start from the root.
If not set, breadcrumbs navigation will start from the parent site as defiend in the ditto call with &parents=``.
If more than one parents site are defined, navigation will start from the root.
Options:
A valid document ID.
Default:
$parents
*/
$bcRootName = isset($bcRootName) ? $bcRootName : 'Home';
/*
Param: bcRootName
Purpose:
Name to be shown for the root folder
Options:
A valid string.
Default:
"Home"
*/
$bcTpl = isset($bcTpl)? template::fetch($bcTpl) : '<a href="[+bcLink+]"><i>[+bcName+]</i></a> <span style="color:#FF7400;">»</span> ';
/*
Param: bcTpl
Purpose:
Template for the crumbs of the breadcrumbs.
Placeholders to be used are:
[+bcID+] : ID of the folder/site. Is empty if root folder.
[+bcLink+] : Link to the folder/site. Can be used as href="[+bcLink+]".
[+bcName+] : Name of the folder/site (=pagetitle).
Options:
A valid chunk name
Default:
"<a href="[+bcLink+]"><i>[+bcName+]</i></a> <span style="color:#FF7400;">»</span> "
*/
$bcTplFirst = isset($bcTplFirst)? template::fetch($bcTplFirst) : $bcTpl;
/*
Param: bcTplFirst
Purpose:
Template for the first crumb of the breadcrumbs.
Placeholders to be used are:
[+bcID+] : ID of the folder/site. Is empty if root folder.
[+bcLink+] : Link to the folder/site. Can be used as href="[+bcLink+]".
[+bcName+] : Name of the site (=pagetitle).
Options:
A valid chunk name
Default:
$bcTpl
*/
$bcTplLast = isset($bcTplLast)? template::fetch($bcTplLast) : '<a href="[+bcLink+]"><b>[+bcName+]</b></a>';
/*
Param: bcTplLast
Purpose:
Template for the last crumb of the breadcrumbs.
Placeholders to be used are:
[+bcID+] : ID of the folder/site. Is empty if root folder.
[+bcLink+] : Link to the folder/site. Can be used as href="[+bcLink+]".
[+bcName+] : Name of the site (=pagetitle).
Options:
A valid chunk name
Default:
"<a href="[+bcLink+]"><b>[+bcName+]</b></a>"
*/
$GLOBALS['ditto_breadcrumbs_params'] = compact('bcStartID','bcRootName','bcTpl','bcTplFirst','bcTplLast');
// ---------------------------------------------------
// Breadcrumbs Functions
// ---------------------------------------------------
if (!function_exists("bcDetermineBreadcrumbs")) {
function bcDetermineBreadcrumbs($resource) {
global $modx;
global $ditto_breadcrumbs_params;
$id = $resource['id'];
$link = '[~'.$id.'~]';
$name = $resource['pagetitle'];
$newcrumb = $ditto_breadcrumbs_params['bcTplLast'];
$newcrumb = str_replace('[+bcID+]',$id,$newcrumb);
$newcrumb = str_replace('[+bcLink+]',$link,$newcrumb);
$newcrumb = str_replace('[+bcName+]',$name,$newcrumb);
$output = $newcrumb;
do {
$parentID = bcGetDocuments(array($id),1,0,'parent');
$parentTitle = bcGetDocuments($parentID[0],1,0,'pagetitle');
$id = isset($parentID[0]['parent'])? $parentID[0]['parent'] : '0';
if (($id==$ditto_breadcrumbs_params['bcStartID']) OR ($id=='0')){
if ($id=='0'){unset($id);}
$link = isset($id)? '[~'.$id.'~]' : '/';
$name = isset($parentTitle[0]['pagetitle'])? $parentTitle[0]['pagetitle'] : $ditto_breadcrumbs_params['bcRootName'];
$newcrumb = $ditto_breadcrumbs_params['bcTplFirst'];
$newcrumb = str_replace('[+bcID+]',$id,$newcrumb);
$newcrumb = str_replace('[+bcLink+]',$link,$newcrumb);
$newcrumb = str_replace('[+bcName+]',$name,$newcrumb);
$output = $newcrumb . $output;
break;
}
$link = '[~'.$id.'~]';
$name = $parentTitle[0]['pagetitle'];
$newcrumb = $ditto_breadcrumbs_params['bcTpl'];
$newcrumb = str_replace('[+bcID+]',$id,$newcrumb);
$newcrumb = str_replace('[+bcLink+]',$link,$newcrumb);
$newcrumb = str_replace('[+bcName+]',$name,$newcrumb);
$output = $newcrumb . $output;
} while (1);
return $output;
}
}
if (!function_exists("bcGetDocuments")) {
function bcGetDocuments($ids= array (), $published= 1, $deleted= 0, $fields= "*", $where= '', $sort= "menuindex", $dir= "ASC", $limit= "") {
global $modx;
if (count($ids) == 0) {
return false;
}
else {
$limit= ($limit != "") ? "LIMIT $limit" : ""; // LIMIT capabilities - rad14701
$tblsc= $modx->getFullTableName("site_content");
$tbldg= $modx->getFullTableName("document_groups");
// modify field names to use sc. table reference
$fields= 'sc.' . implode(',sc.', preg_replace("/^\s/i", "", explode(',', $fields)));
$sort= ($sort == "") ? "" : 'sc.' . implode(',sc.', preg_replace("/^\s/i", "", explode(',', $sort)));
if ($where != '')
$where= 'AND ' . $where;
// get document groups for current user
if ($docgrp= $modx->getUserDocGroups())
$docgrp= implode(",", $docgrp);
$sql= "SELECT DISTINCT $fields FROM $tblsc sc
LEFT JOIN $tbldg dg on dg.document = sc.id
WHERE (sc.id IN (" . join($ids, ",") . ") AND sc.published=$published AND sc.deleted=$deleted $where)
GROUP BY sc.id " .
($sort ? " ORDER BY $sort $dir" : "") . " $limit ";
$result= $modx->dbQuery($sql);
$resourceArray= array ();
for ($i= 0; $i < @ $modx->recordCount($result); $i++) {
array_push($resourceArray, @ $modx->fetchRow($result));
}
return $resourceArray;
}
}
}
?>