GetIBlockElementListEx
CIBlockResult GetIBlockElementListEx ( string type, mixed TypesInc = Array(), mixed TypesExc = Array(, array Order = Array("SORT"=>"ASC"), int cnt = 0, array arFilter = Array(), array arSelect = Array(), mixed arGroupBy = false );
The function returns active elements of the information block type defined by type. The elements returned are active within the current site.
Parameters
Parameter | Description |
---|---|
type | Type of information blocks to search for elements. |
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:
Default value is Array("sort"=>"asc"). Full list of sorting fields and additional information can be found in CIBlockElement::GetList() |
cnt | Maximum number of the returned records. Optional. All records are returned by default. |
arFilter | Optional additional filter by fields in the form of Array("Filtered field"=>"Value",
...). The
Filtered field can be the following:
The fields SECTION_ID and ACTIVE_DATE may have negation sign ("!") before the name. The "filter values" are a single value or an array. The default parameter value is an empty array. Full list of sorting fields and additional information can be found in CIBlockElement::GetList() |
arSelect | Array containing the element fields to retrieve. Allows to get the property
values immediately. To do so, set the name of one of the fields to PROPERTY_<PROPERTY_CODE>
where PROPERTY_CODE is the ID or mnemonic code. The result will contain
values of the element properties as fields:
By default, all the element fields are retrieved. |
arGroupBy | Array of fields for grouping. If specified, the selection becomes grouped by
these fields, and the result contains the CNT field (number of grouped
elements). If an empty array is passed, the function returns the number of
elements in the CNT field. Grouping is possible by the element fields as well as the property values. If the latter is the case, set one of the grouping fields to PROPERTY_<PROPERTY_CODE> where PROPERTY_CODE is the ID or mnemonic code of the properties. Optional. By default, records are not grouped. |
Return Values
The function returns an instance of CIBlockResult with active elements, i.e. those having the flag Active set, valid active period and pertaining to the active parent information blocks of the current site.
Remarks
To facilitate handling the function return values, you can use the method CDBResult::GetNext()
returning an array of the information block element fields. All fields returned
by this method are HTML compliant and safe. Variables #SITE_DIR#
, #IBLOCK_ID#
, #EXTERNAL_ID#
and #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
Example
<? if(CModule::IncludeModule("iblock")) { // select 15 elements of the type "news" // from the information block "company_news" $items = GetIBlockElementListEx("news", "company_news", Array(), Array("DATE_ACTIVE_FROM"=>"DESC", "SORT"=>"ASC", "NAME" => "ASC"), 15); // page navigation $items->NavPrint("Company news"); // loop on news while ($arItem = $items->GetNext()) { // display a link to the detailed view echo "<a href='".$aritem["detail_page_url"]."'>".$aritem["name"]."</a>"; // display data echo $arItem["DATE_ACTIVE_FROM"]."<br>"; // display the preamble image with the link to the detailed view echo ShowImage($arItem["PREVIEW_PICTURE"], 100, 100, "border='0'", $arItem["DETAIL_PAGE_URL"]); // display the preamble echo $arItem["PREVIEW_TEXT"]."<hr>"; } $items->NavPrint("Company news"); } ?>
<? // Display news for today (DATE_ACTIVE_FROM >= today): $items = GetIBlockElementListEx("news", Array(), Array(), Array("SORT"=>"ASC", "ID" => "DESC"), 15, Array( ">=DATE_ACTIVE_FROM"=>date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT"))) ) ); // Display news for yesterday (DATE_ACTIVE_FROM >= yesterday && DATE_ACTIVE_FROM < today): $items = GetIBlockElementListEx("news", Array(), Array(), Array("SORT"=>"ASC", "ID" => "DESC"), 15, Array( ">=DATE_ACTIVE_FROM"=>date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), mktime(0,0,0,date("m"), date("d")-1, date("Y"))), "<DATE_ACTIVE_FROM"=>date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), mktime(0,0,0,date("m"), date("d"), date("Y"))) ) ); // Display news for 01.01.2003 (DATE_ACTIVE_FROM >= 01.01.2003 && DATE_ACTIVE_FROM < 02.01.2003): $items = GetIBlockElementListEx("news", Array(), Array(), Array("SORT"=>"ASC", "ID" => "DESC"), 15, Array( ">=DATE_ACTIVE_FROM"=>date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), mktime(0,0,0,1,1,2003)), "<DATE_ACTIVE_FROM"=>date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), mktime(0,0,0,1,2,2003)) ) ); ?>