The code sample below displays the entries from the bitrix database on the page, but displays them in the order “From the old date to the new one” (field DATE_ACTIVE_FROM ).

How to change the output in the order "From the new date to the old"?

  <?if( !empty($arItem["VIEW"]) ):?> <ul class="short-news"> <?foreach ($arItem["VIEW"] as $key => $value):?> <li> <? $date = explode(" ", $value['DATE_ACTIVE_FROM']); ?> <? $date[0] = str_replace('/','.',$date[0]); ?> <span class="sn-date"><?=$date[0]?></span> <noindex><a target="_blank" class="exp-news-name" rel="nofollow" href="<?=$value['PROPERTY_LINK_VALUE']?>"><?=$value['NAME']?></a></noindex> <span class="clear"></span> </li> <?endforeach;?> </ul> <?endif;?> 
  • one
    It is necessary to find where it generates data and change the sorting. - Naumov
  • If you output using a component, then in its settings there are options on how to sort in ascending or descending order. If you pick it up from the database, you can also set it there, but you need to look at the code as you make the selection. - Nikolaj Sarry
  • Do you use component or Bitrix API? - Rustembek Kaliyev

1 answer 1

Here is the link to the news-list component documentation. If you use the news-list component for data output, the order in which they are output is determined by the parameter

 "SORT_BY1" => "ACTIVE_FROM", "SORT_ORDER1" => "DESC", 

on the component call page. This is much more convenient than sorting data inside a template.