There is such an information block structure

1.Раздел --1.1 Элемент --1.2 Элемент --1.3 Элемент 2.Раздел --2.1 Элемент --2.1 Элемент 

Tell me how can I display it in this form?

 if(CModule::IncludeModule("iblock")){ $IBLOCK_ID = 6; // указываем из какого инфоблока берем элементы $arOrder = Array("SORT"=>"ASC"); // сортируем по свойству SORT по возрастанию $arSelect = Array("ID", "NAME", "IBLOCK_ID", "DETAIL_PAGE_URL"); $arFilter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE"=>"Y"); $res = CIBlockElement::GetList($arOrder, $arFilter, false, false, $arSelect); while($ob = $res->GetNextElement()) { $arFields = $ob->GetFields(); // берем поля echo $arFields['NAME']."<br>"; //echo "<pre>";var_dump($arFields);echo "</pre>"; } echo "<br>"; $arFilter = Array('IBLOCK_ID'=>$IBLOCK_ID, 'GLOBAL_ACTIVE'=>'Y'); $list = CIBlockSection::GetList($arOrder, $arFilter, true); while($ar_result = $list->GetNext()) { echo $ar_result['NAME'].'<br>'; }} 
  • In the cycle for selecting sections, place the cycle for selecting elements - EatMyDust
  • @EatMyDust added as you wrote, but nothing happened ideone.com/GEI8Ck - ChromeChrome
  • Because in arFilter, which is inside the cycle of sections, it is necessary to transmit the id of the information block of the section - EatMyDust

1 answer 1

Here's the answer, who can come in handy

 <? CModule::IncludeModule("iblock"); $IBLOCK_ID = 6; $aMenuLinksNew = Array(); $arFilter = array('IBLOCK_ID'=>$IBLOCK_ID, 'ACTIVE'=>'Y'); $rsSect = CIBlockSection::GetList(Array("SORT"=>"ASC"), $arFilter, false, array("IBLOCK_ID", "ID", "NAME", "SECTION_PAGE_URL")); while ($arSect = $rsSect->GetNext()) { $aMenuLinksNew[] = array( $arSect["NAME"], $arSect["SECTION_PAGE_URL"], array(), array("SECTION"=>true, "DEPTH_LEVEL"=>2), "" ); $arSelect = Array("ID", "NAME", "DETAIL_PAGE_URL"); $arFilterElem = Array('IBLOCK_ID'=>$IBLOCK_ID, "SECTION_ID"=>$arSect["ID"], "ACTIVE"=>"Y"); $res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilterElem, false, false, $arSelect); if($arFields = $res->GetNext()) { $aMenuLinksNew[] = array( $arFields["NAME"], $arFields["DETAIL_PAGE_URL"], array(), array("SECTION"=>false, "DEPTH_LEVEL"=>3), "" ); } } $aMenuLinks = array_merge($aMenuLinks, $aMenuLinksNew); 

?>