Created
December 16, 2019 08:13
-
-
Save crystaldaking/6891b09decd21d9a6082ef1a8bd56a76 to your computer and use it in GitHub Desktop.
brandsbuilder.php
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 | |
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