Skip to content

Instantly share code, notes, and snippets.

@crystaldaking
Created December 16, 2019 08:13
Show Gist options
  • Save crystaldaking/6891b09decd21d9a6082ef1a8bd56a76 to your computer and use it in GitHub Desktop.
Save crystaldaking/6891b09decd21d9a6082ef1a8bd56a76 to your computer and use it in GitHub Desktop.
brandsbuilder.php
<?php
if(empty($parent)) {
$parent = 2;
$tplOuter = 'tpl_brands';
$tplItem = '@INLINE <a href="[[+uri]]">[[+pagetitle]]</a><br/>';
}
//Получаем список заглавных букв
$letters = $modx->runSnippet('pdoResources', array(
'parents'=> $parent,
'tpl'=> '@INLINE {$pagetitle | limit:1}',
'sortby'=>'{"pagetitle":"ASC"}',
'limit'=> 0,
'outputSeparator'=>'|'
));
//Загоняем в массив
$arr = explode('|', $letters);
//Выбрасываем повторы
$uarr = array_unique($arr);
//пробегаемся циклом и выводим те ресурсы, pagetitle которых имеет первую букву, совпадающую с $char
foreach($uarr as $char) {
$list = $modx->runSnippet('pdoResources', array(
'parents'=> $parent,
'where'=>'{"pagetitle:LIKE":"'.$char.'%"}',
'tpl'=> $tplItem,
'sortby'=>'{"pagetitle":"ASC"}',
'includeTVs' => 'previewImage',
'limit'=> 0
));
$out .= $modx->getChunk($tplOuter, array(
'char' => $char,
'items' => $list
));
}
return $out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment