Answer the question
In order to leave comments, you need to log in
How to correct this snippet for ModX?
Good day. There is a snippet code
<?php
/**
* Входной параметр $max.
* Сколько заголовков нужно выводить.
*/
$max = (isset($max)) ? $max : "20";
$dID = $modx->documentIdentifier; // Получаем ID просматриваемого документа.
$parentId = array_pop($modx->getParentIds($modx->documentIdentifier,1)); // Получаем родителя.
$children = $modx->getActiveChildren($parentId,'menuindex','ASC');
$j=0;
$key = false;
while(!$key && $j<count($children)){
$key = array_search($dID,$children[$j]);
$j++;
}
$output = '<ul>';
// Цикл показа постов
if(!empty($key) && count($children)>1) {
for ($i=1;$i<$max+2;$i++) {
if ($j-$i>=0) {
$simular = $modx->getDocument($children[$j - $i]['id'], "pagetitle");
if ($children[$j - $i]['id']!=$dID)
$output .= '<li class="related-list"><a href="'.$modx->makeUrl($children[$j - $i]['id']).'">'.$simular['pagetitle'].'</a></li>';
}
}
}
echo $output.'</ul>';
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question