V
V
Vladimir2017-05-05 19:54:40
1C-Bitrix
Vladimir, 2017-05-05 19:54:40

How to make navigation in bitrix news detail sorted by active date?

Hello.
My code. I display internal navigation in bitrix news detail.
Modifier:

<?
$res = CIBlockElement::GetList(Array("ID"=>"ASC", "ACTIVE"=>"Y"), Array("IBLOCK_CODE"=>"news", "ACTIVE"=>"Y"), false);
  while ($RR = $res->GetNext()) {
    if ($RR["ID"] < $arResult["ID"]) {
      $prev = $RR["DETAIL_PAGE_URL"];			
    }
    if ($RR["ID"] > $arResult["ID"]) {
      $next = $RR["DETAIL_PAGE_URL"];	
      break;
    }
  }
    
  $arResult["PREV_LINK"] = $prev;
  $arResult["NEXT_LINK"] = $next;
?>

template
<table class="news_nav" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="prev_news"><?if(!empty($arResult["PREV_LINK"])):?><a href="<?=$arResult["PREV_LINK"]?>">Предыдущая новость</a><?endif?></td>
    <td class="all_news"><a href="/news/">Все новости</a></td>
    <td class="next_news"><?if(!empty($arResult["NEXT_LINK"])):?><a href="<?=$arResult["NEXT_LINK"]?>">Следующая новость</a><?endif?></td>
  </tr>
</table>

It turns out that he does internal navigation for me by ID. That is, the main news is sorted by the activity date, and navigation by id turns out to be wrong, how can I make the detail have something like if the activity date of the current news < the activity date of the next news, then we display a link to the next news, like this, all in all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
no_one_safe, 2017-05-05
@no_one_safe

Your sorting is "ACTIVE"=>"Y"
Read this - https://dev.1c-bitrix.ru/api_help/iblock/classes/c...
The active date field is "DATE_ACTIVE_FROM"

A
Alexey Burlaka, 2017-05-06
@AlexeyGfi

$res = CIBlockElement::GetList(
  Array(
      'DATE_ACTIVE_FROM' => 'ASC'
  ),
  Array("IBLOCK_CODE"=>"news", "ACTIVE"=>"Y"),
  false,
  false,
  [   указывайте, какие поля читать.
    Не тяните целую колбасу, когда вам нужно всего пару полей
  ]
);

And further.
"nElementID" - the ID of the element that will be selected along with its neighbors...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question