Created
October 14, 2021 14:34
-
-
Save eagles038/e6856bcc3e5d848d3a06b79fdde484d0 to your computer and use it in GitHub Desktop.
bitrix Получить имя или ID раздела по SECTION_CODE в Битрикс
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
| Сначала получаем id нашего раздела. Для этого воспользуемся очень удобным, но не документированным (ох уж этот Битрикс) классом CIBlockFindTools и его методом GetSectionID. В section.php перед выводом нашего заголовка пишем: | |
| $arResult["SECTION_ID"] = CIBlockFindTools::GetSectionID( | |
| $arResult["VARIABLES"]["SECTION_ID"], | |
| $arResult["VARIABLES"]["SECTION_CODE"], | |
| array("IBLOCK_ID" => $arParams["IBLOCK_ID"]) | |
| ); | |
| $res = CIBlockSection::GetByID($arResult["SECTION_ID"]); | |
| if($ar_res = $res->GetNext()) { | |
| $sectionName = $ar_res['NAME']; | |
| } | |
| Можно вывести и не имя, а любое другое поле, например UF_TITLE =) | |
| Значит для получения любого поля раздела инфоблока нам достаточно знать только SECTION_CODE нужного инфоблока. Данный код работает при включенном ЧПУ и уникальности символьного кода раздела. | |
| $arResult["ELEMENT_ID"] = CIBlockFindTools::GetElementID( | |
| $arResult["VARIABLES"]["ELEMENT_ID"], | |
| $arResult["VARIABLES"]["ELEMENT_CODE"], | |
| false, | |
| false, | |
| array( | |
| "IBLOCK_ID" => $arParams["IBLOCK_ID"], | |
| "IBLOCK_LID" => SITE_ID, | |
| "IBLOCK_ACTIVE" => "Y", | |
| "ACTIVE_DATE" => "Y", | |
| "ACTIVE" => "Y", | |
| "CHECK_PERMISSIONS" => "Y", | |
| ) | |
| ); | |
| А так можно получить количество подразделов в разделе | |
| $arFilter = Array( | |
| "IBLOCK_ID"=>$arParams['IBLOCK_ID'], | |
| "SECTION_ID"=>$arResult["SECTION_ID"] | |
| ); | |
| echo CIBlockSection::GetCount($arFilter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment