M
M
Maxim Volkov2019-09-23 16:31:54
1C-Bitrix
Maxim Volkov, 2019-09-23 16:31:54

Bitrix GetList - how to get the most viewed elements of the infoblock?

Task: Display the five most viewed news from the infoblock.
According to the documentation , CIBlockElement::GetList allows you to select and sort by the SHOW_COUNTER property , which contains data on the number of infoblock element views.
1. I can't figure out how to write a query to select data, where is the number in SHOW_COUNTER the most?
2. Would it be optimal to get CIBlockElement::GetList - sorted by SHOW_COUNTER values ​​and limit the "nTopCount" => 5 limit?
3. Are there more rational options for solving this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Volkov, 2019-09-23
@voland700

Issue resolved. Perhaps the solution is useful to someone, I will describe the solution.
Using CIBlockElement::GetList - get a list of infoblock elements, sort in descending order by the SHOW_COUNTER field - which contains data on the number of views, and limit the limit to 5 elements.

if(CModule::IncludeModule('iblock'))
{
  $res = CIBlockElement::GetList(
    array("SHOW_COUNTER"=>"DESC"), // сортировка по количеству просмотров;
    array("IBLOCK_ID"=>1," ACTIVE"=>"Y"), //Получаем  активные элементы , в данном случае из инфоблока с ID = 1;
    false, 
    array("nTopCount"=>5), //ограничиваем количество элементов - только 5.
    array("NAME","PREVIEW_PICTURE", "DETAIL_PAGE_URL")// Выбираем только указанные поля
  ); 
  while($ar = $res->GetNext())
  {
    $arTheBest[]=$ar;	//массив с данными 5 самых просматриваемых элементов инфоблока				
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question