Documentation

GetIBlockList

CDBResult
GetIBlockList (
 string type, 
 mixed TypesInc = array(), 
 mixed TypesExc = array(), 
 array Order = array("SORT"=>"ASC"), 
 int cnt = 0
);

The function returns information blocks of the type type. The blocks returned are active within the current site.

Parameters

Parameter Description
type Type of information blocks.
TypesInc Allows to set the filter that describes information blocks included in the selection. The filter uses the ID or mnemonic code of an information block as the match criteria. You can use either a single value or an array of values here.
This parameter is optional. By default, all elements of information blocks of the matching type is selected.
Example: "product_news".
TypesExc Similar to TypesInc, but sets the filter to exclude the matching information blocks. 
This parameter is optional. By default, all elements of information blocks of the matching type is selected.
Example: Array("company_news", "product_news", 22).
Order Optional sort order. Array of the format Array(by1=>order1[, by2=>order2 [, ..]]) where by is the field for sorting. The field can have the following values:
  • id - element ID;
  • sort - sort weight;
  • timestamp_x - modification date;
  • name - name.
order is the sort order. Can be asc for ascending sorts or desc for descending.

Default value is Array("sort"=>"asc").
cnt Maximum number of the returned records. Optional. All records are returned by default.

Return Values

The function returns an instance of CIBlockResult with active blocks of the current site (from within which the function is called), i.e. those having the flag Active set.

Remarks

To facilitate handling the function return values, you can use the method CDBResult::GetNext() returning an array of the information block fields. All fields returned by this method are HTML compliant and safe. Variables #SITE_DIR# and #IBLOCK_ID# are replaced with their corresponding values (fields LIST_PAGE_URL and DETAIL_PAGE_URL). If the result is empty or the end of collection is reached, false is returned. 
Other methods of the CDBResult class can also be used, but keep in mind that they do not substitute variables like #SITE_DIR# with their values.

See Also

  • Fields of an information block
  • Example


    <?
    if(CModule::IncludeModule("iblock"))
    {
       // select all information blocks of the type "catalog"
       $iblocks = GetIBlockList("catalog");
       while($arIBlock = $iblocks->GetNext()) // loop on all blocks
       {
          // do not call function htmlspecialchars($arIBlock["NAME"]), 
          // as the method GetNext() does
          echo "Name: ".$arIBlock["NAME"]."<br>"; 
       }
    }
    
    ?>

    <?
    if(CModule::IncludeModule("iblock"))
    {
       // select 5 information blocks of the type "news" sorted by name
       // except those with the mnemonic code "company_news"
       $iblocks = GetIBlockList(
                   "news", 
                   Array(), 
                   "company_news", 
                   Array("name"=>"asc"), 
                   5);
    
       // loop on information blocks
       while($arIBlock = $iblocks->GetNext()): 
       ?>
           // make a link to the news page
           <a href="<?echo $arIBlock["LIST_PAGE_URL"]?>"><?echo $arIBlock["NAME"]?></a><br>
           <?
           // select 5 last news from each block
           $items = GetIBlockElementList(
                       $arIBlock["ID"], 
                       false, 
                       Array("ACTIVE_FROM"=>"desc", "sort"=>"asc"), 
                       5);
           while($arItem = $items->GetNext())
           {
                // display news
           }
       endwhile;
    }
    ?>
    © «Bitrix24», 2001-2024
    Up