Created
October 12, 2023 10:53
-
-
Save eagles038/8711d90538fe3b51d53413e4542492f7 to your computer and use it in GitHub Desktop.
Фильтр по алфавиту
This file contains hidden or 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
| // Русский алфавит | |
| $ru = array( | |
| 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ж', 'З', 'И', 'К', 'Л', 'М', | |
| 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', | |
| 'Э', 'Ю', 'Я' | |
| ); | |
| // Английский алфавит | |
| $en = array( | |
| 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', | |
| 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' | |
| ); | |
| $items = []; | |
| $arSelect = Array("ID", "NAME", "DETAIL_PAGE_URL", "PREVIEW_PICTURE", "DETAIL_PICTURE"); | |
| $arFilter = Array("IBLOCK_ID" => 5, "ACTIVE"=>"Y"); | |
| $res = CIBlockElement::GetList(array(), $arFilter, false, array(), $arSelect); | |
| while($Element = $res->Fetch()) { | |
| $items[] = $Element; | |
| }; | |
| // Компонуем массив в виде буква => все записи | |
| $data = array(); | |
| foreach ($items as $list_row) { | |
| foreach ($en as $row) { | |
| if (mb_substr($list_row["NAME"], 0, 1) == $row) { | |
| $data[$row][] = mb_substr($list_row["NAME"], 0, 1); | |
| } | |
| } | |
| foreach ($ru as $row) { | |
| if (mb_substr($list_row["NAME"], 0, 1) == $row) { | |
| $data[$row][] = mb_substr($list_row["NAME"], 0, 1); | |
| } | |
| } | |
| } | |
| <div class="pointer"> | |
| <?php | |
| foreach ($en as $row) { | |
| if (empty($data[$row])) { | |
| echo '<span>' . $row . '</span>'; | |
| } else { | |
| echo '<a href="#' . $row . '">' . $row . '</a>'; | |
| } | |
| } | |
| ?> | |
| </div> | |
| <div class="pointer"> | |
| <?php | |
| foreach ($ru as $row) { | |
| if (empty($data[$row])) { | |
| echo '<span>' . $row . '</span>'; | |
| } else { | |
| echo '<a href="#' . $row . '">' . $row . '</a>'; | |
| } | |
| } | |
| ?> | |
| </div> | |
| <?php | |
| foreach ($data as $i => $items) { | |
| if (!empty($items)) { | |
| $items = array_chunk($items, ceil(count($items) / 5)); | |
| ?> | |
| <h2 id="<?php echo $i; ?>"><?php echo $i; ?></h2> | |
| <table class="list"> | |
| <tr> | |
| <?php foreach ($items as $item): ?> | |
| <td> | |
| <ul> | |
| <?php foreach ($item as $row): ?> | |
| <li><a href="#"><?php echo $row['name']; ?></a></li> | |
| <?php endforeach; ?> | |
| </ul> | |
| </td> | |
| <?php endforeach; ?> | |
| </tr> | |
| </table> | |
| <?php | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment