N
N
NakedFace2016-01-06 10:52:24
PHP
NakedFace, 2016-01-06 10:52:24

How to get the number of elements in a Bitrix section without subsections?

Hello!
The standard template has this way of counting elements

$arItemFilter = CAllCorp::GetCurrentSectionElementFilter($arResult["VARIABLES"], $arParams);
$itemsCnt = CCache::CIblockElement_GetList(array("CACHE" => array("TAG" => CCache::GetIBlockCacheTag($arParams["IBLOCK_ID"]))), $arItemFilter, array());

But for unknown reasons, in some cases it returns 0, even if there are elements in the section.
Tell me how to return exactly the number of elements in the section, not taking into account the subsections. You can say the number of products that are displayed on the page, and if this page has subsections, then they and their content are not taken into account.
CIBlockSection::GetSectionElementsCount($SectionID);

returns the number of section items along with subsections
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-01-06
@NakedFace

Try something like this:

<?
  $arFilter = array('IBLOCK_ID' => 8, 'DEPTH_LEVEL'=>'1', 'SECTION_ID'=false);
  $res = CIBlockElement::GetList(false, $arFilter, array('IBLOCK_ID'));
  if ($el = $res->Fetch()){
    echo GetMessage("CT_CMM").$el['CNT'];
  }
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question