Answer the question
In order to leave comments, you need to log in
Displaying the required number of elements on the Bitrix page?
Good afternoon! There is a method that displays a given number of elements.
Before calling bitrix:catalog.section
<?
$pageElementCount = "10";
if (array_key_exists("showBy", $_REQUEST)) {
if ( intVal($_REQUEST["showBy"]) && in_array(intVal($_REQUEST["showBy"]), array(18, 36, 54, 72)) ) {
$pageElementCount = intVal($_REQUEST["showBy"]);
$_SESSION["showBy"] = $pageElementCount;
} elseif ($_SESSION["showBy"]) {
$pageElementCount = intVal($_SESSION["showBy"]);
}
}
?>
<div class="text-right">
<span class="show_title">Показать по </span>
<span class="number_list">
<? for ($i = 18; $i <= 72; $i+=18) : ?>
<a rel="nofollow" <? if ($i == $pageElementCount): ?>class="current"<? endif; ?>
href="<?= $APPLICATION->GetCurPageParam('showBy=' . $i, array('showBy', 'mode')) ?>"
>
<span><?= $i ?></span>
</a>
<? endfor; ?>
</span>
</div>
Answer the question
In order to leave comments, you need to log in
It is written to the session, checked, but it is not clear why exactly to write to the session and the logic as a whole ...
По умолчанию $pageElementCount = "10", далее
Если в $_REQUEST есть showBy, то
Если showBy соответствует значению 18, 36, 54, 72,
pageElementCount = $_REQUEST['showBy']
пишем в $_SESSION
Если не соответствует
pageElementCount = $_SESSION['showBy']
$arAvailableCounts = array(18, 36, 54, 72);
$pageElementCount = isset($_COOKIE['showBy']) && intval($_COOKIE['showBy']) ? $_COOKIE['showBy'] : $arParams['PAGE_ELEMENT_COUNT'];
if(isset($_GET['showBy']) && $_GET['showBy'] && in_array($_GET['showBy'], $arAvailableCounts)) {
$pageElementCount = $_GET['showBy'];
setcookie('showBy', $_GET['showBy'], 0, SITE_DIR);
}
<div class="text-right">
<span class="show_title">Показать по </span>
<span class="number_list">
<?foreach($arAvailableCounts as $value):?>
<a class="<?=($value == $pageElementCount ? 'current' : '');?>" href="<?=$APPLICATION->GetCurPageParam('showBy='.$value, array('showBy'));?>" rel="nofollow"><span><?=$value;?></span></a>
<?endforeach;?>
</span>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question