Z
Z
ZeXeDeR2015-05-02 17:38:39
MODX
ZeXeDeR, 2015-05-02 17:38:39

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>';
?>

The snippet finds the parent resource and displays the full list of child resources. At the moment, it only outputs the resources following the one that is currently active. I can’t figure out how to make him also display a list of resources, up to the active one. In general, the task is to display siblings, but as far as I know, there is no ready-made solution in Evo. Therefore I am perverted I sit.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanes, 2015-05-02
@ZeXeDeR

Wayfinder doesn't fit?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question