Skip to content

Instantly share code, notes, and snippets.

@Fi1osof
Forked from Tramp1357/breadcrumbs.class.php
Last active February 8, 2016 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Fi1osof/c2087b988a679bd699c3 to your computer and use it in GitHub Desktop.
Save Fi1osof/c2087b988a679bd699c3 to your computer and use it in GitHub Desktop.
<?php
class modSiteWebBreadcrumbsProcessor extends modProcessor{
public function initialize(){
$this->setDefaultProperties(array(
'startId' => 0,
'excludeDocs' => array(),
'showHidden' => true,
'showUnpub' => false,
'showDeleted' => false
));
return parent::initialize();
}
public function process() {
$bc_path = array();
$resource = $this->modx->resource;
//стоим в голове, нечего выводить
if($resource->get('id') != $this->getProperty('startId')){
//соберем цепочку родителей
$r=$resource->toArray();
unset($r['content']);
$bc_path[]=$r;
while($resource = $resource->getOne('Parent')) {
if (in_array($resource->id, $this->getProperty('excludeDocs'))
|| !$this->getProperty('showHidden') && $resource->hidemenu
|| !$this->getProperty('showUnpub') && !$resource->published
|| !$this->getProperty('showDeleted') && $resource->deleted
){
continue;
}
$r=$resource->toArray();
unset($r['content']);
array_unshift($bc_path,$r);
if($resource->id==$this->getProperty('startId')) break;
}
}
return $this->success('', $bc_path);
}
}
return 'modSiteWebBreadcrumbsProcessor';
{$params=['startId'=>37]}
{processor action='site/web/breadcrumbs' ns=modxsite params=$params assign=result}
<div class="breadcrumbs">
{$total = count($result['object'])}
{$counter = 0}
{foreach $result.object as $object}
{$counter=$counter+1}
{if $counter<$total}
<span itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<a itemprop="url" rel="{$object.pagetitle}" href="{$object.uri}">
<span itemprop="title">{$object.pagetitle}</span></a></span>
/
{else}
<span itemscope="itemscope">{$object.pagetitle}</span>
{/if}
{/foreach}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment