<?php $id = isset($docid) ? $docid : $modx->documentIdentifier; $d = isset($depth) ? $depth : 0; $fs = isset($fields) ? $fields: 0; $da = $modx->getChildIds($id, $d); $df = $modx->getDocuments($da,$fields=($fs)); return (count($da) - count($df)); ?>
попробовал у меня если в папке нет вложенных документов пишет (-1)
[[ChildCounter? &docid=`15` &depth=`3` &fields=`isfolder`]]
Данный вызов выведет только документы, не являющиеся родителями (папками).
Нужные для вывода дополнительные параметры (unpublished, showinmenu и т.п.) указываем при необходимости в $fields через запятую.
<?php $docid = isset($docid) ? intval($docid) : $modx->documentIdentifier; $depth = isset($depth) ? intval($depth) : 0; $isfolder = isset($isfolder) ? intval($isfolder): 0; $published = isset($published) ? intval($published): 1; $davailable = $modx->getChildIds($docid, $depth); $dcount = $modx->getDocuments($davailable, $published, 0, 'id', 'isfolder='.$isfolder); return count($dcount); ?>
<?php $id = isset($docid) ? $docid : $modx->documentIdentifier; $d = isset($depth) ? $depth : 0; $published = isset($published) ? $published: 1; $tpl= isset($tpl) ? $tpl: 1; $da = $modx->getChildIds($id, $d); $count=0; foreach ($da as $key){ $txt = $modx->getDocument($key,'template',$published); if($txt['template'] == $tpl){$count++;} } return $count; ?>
[[ChildCounter? &docid=`[+wf.docid+]`&depth=`2`&tpl=`8`]]
<?php $docid = isset($docid) ? intval($docid) : $modx->documentIdentifier; $depth = isset($depth) ? intval($depth) : 0; $isfolder = isset($isfolder) ? intval($isfolder): 0; $tpl = isset($tpl) ? $tpl: -1; $published = isset($published) ? intval($published): 1; $davailable = $modx->getChildIds($docid, $depth); $where = ($tpl > 0) ? 'template='.$tpl : 'isfolder='.$isfolder; $dcount = $modx->getDocuments($davailable, $published, 0, 'id', $where); return count($dcount); ?>
Каталог авто -AC 7 -Acura 7 --CL 7 ---Машинка первая 8 --EL 7 ---Машинка вторая 8 --Integra 7 -Alfa Romeo 7 --145 7 --CZ 7 --Sport Vagon 7
AC 1 Acura 2 Alfa Romeo 0