L
L
lamer3502019-02-27 23:09:39
1C-Bitrix
lamer350, 2019-02-27 23:09:39

Bitrix, how to set a custom amount of news for pagination?

There is a news page, on it initially (on 1 page it turns out) 4 news are displayed (design features, 3 columns + 1 news in full width), then using ajax I load 6 news each. (2 rows x 3 columns).
But in this scenario, 2 news are lost, since the second page is obtained from the 7th news.
How can I adjust the values ​​so that in the pagination, when calculating the indexes of the news that you want to display on this page, an adjustment for -2 indexes is applied? and instead of from 7 to 12 they took from 5 to 10?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kudis, 2019-03-04
@lamer350

Standard news.list is not a solution,
you can write your own component. here is the base:

CModule::IncludeModule("iblock");

$arSelect = [
    'ID',
    'NAME',
];

$arFilter = [
    'IBLOCK_CODE' => 'news',
];

if ($_REQUEST['PAGEN_1'] > 1) {
    $arNavStartParams = [
        'iNumPage' => $_REQUEST['PAGEN_1'] - 1,
        'nPageSize' => 6,
    ];
    $arFilter['!ID'] = [1, 2, 3, 4]; // TODO: получить эти данные в запросе и закешировать
} else {
    $arNavStartParams = [
        'nTopCount' => 0,
        'iNumPage' => 1,
        'nPageSize' => 10,
    ];
}

$obFields = CIBlockElement::GetList(
        ['ID' => 'asc'],
        $arFilter,
        false,
        $arNavStartParams,
        $arSelect
);

$arCurrentData = [];

while($arField = $obFields->Fetch()) {
    print_r($arField);
}

Pay attention to TODO - this is the id of the first 4 news - get them from the same component, showing the 1st page
, starting from the second page, we do a certain offset, prohibiting the display of already displayed news in the 1st four and shifting the paginator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question