M
M
Maxim2020-04-14 14:29:44
1C-Bitrix
Maxim, 2020-04-14 14:29:44

How to make navigation buttons Previous, Next article?

We have an infoblock with sections in each section of the article. It is necessary to make the navigation buttons Previous, Next article in the detailed view of the Article.5e959e0c9a769427896995.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2020-04-14
@alexprowars

function getNeighboringItems ($elementId, $sort = [], $filter = [])
  {
    Loader::includeModule('iblock');

    $arrows = [];

    $elements = CIBlockElement::GetList($sort, $filter, false, ['nElementID' => $elementId, 'nPageSize' => 1], ['ID', 'NAME', 'DETAIL_PAGE_URL']);

    while ($element = $elements->GetNext())
      $arrows[] = $element;

    $result = ['LEFT' => [], 'RIGHT' => []];

    if (count($arrows) == 3)
    {
      $result['LEFT'] = $arrows[0];
      $result['RIGHT'] = $arrows[2];
    }
    elseif (count($arrows) == 2)
    {
      if ($arrows[0]['ID'] != $elementId)
        $result['LEFT'] = $arrows[0];
      if ($arrows[1]['ID'] != $elementId)
        $result['RIGHT'] = $arrows[1];
    }

    return $result;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question