Last active
December 3, 2019 08:54
-
-
Save crystaldaking/12538431f8660ea0e550a2b79f0fc770 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//проверяем есть ли параметр $parent. Если нет используем ID текущего ресурса. | |
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"}', | |
'limit'=> 0 | |
)); | |
$out .= $modx->getChunk($tplOuter, array( | |
'char' => $char, | |
'items' => $list | |
)); | |
} | |
return $out; | |
вывод: | |
tpl_brands = <div class="d-flex b-title"> | |
<h2 class="title-section mr-2 mr-lg-4 mb-4">{$char}</h2> | |
</div> | |
{$items} | |
{$_modx->runSnippet('brands', [ | |
'parent' => 2, | |
'tplOuter' => 'tpl_brands', | |
'tplItem' => '@INLINE <a href="{$uri}">{$pagetitle}</a><br />' | |
])} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment