S
S
SteepNET2019-12-21 21:05:30
1C-Bitrix
SteepNET, 2019-12-21 21:05:30

Different sorting on click?

Good afternoon! Tell me how to make the change of sort values ​​more beautiful when clicking on the link?

<a <? if ($_GET["sort"] == "catalog_PRICE_1"): ?><? endif;?>
href="<?= $arResult["SECTION_PAGE_URL"] ?>?sort=catalog_PRICE_1&method=asc">
<?= Loc::getMessage("PRICE") ?>
</a>

In the code, method= can take the values
​​asc - ascending;
desc - descending;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2019-12-22
@SteepNET

1. It is better to replace the href attribute in the link with a bitrix function, this will save other GET parameters, if any

<?=$APPLICATION->GetCurPageParam('sort=указываешь поле для сортировки, в твоем случае catalog_PRICE_1&method=указываешь направление сортировки (ASC, DESC)', array('sort', 'method'))?>

!! replace method with order, it will be more logical)
2. If the component is complex:
go to the file where you connect a simple component and substitute parameters from $_GET
$sort = !empty($_GET['sort']) ? $_GET['sort'] : $arParams['SORT_BY1'];
$method = !empty($_GET['method']) ? $_GET['method'] : $arParams['SORT_ORDER1'];

news component :
"SORT_BY1" => $sort,
"SORT_ORDER1" => $method,

catalog component :
"ELEMENT_SORT_FIELD" => $sort,
"ELEMENT_SORT_ORDER" =>	$method,

PS it's better to add an array of possible fields for sorting and check that the parameter from $_GET corresponds to what is in this array, so that even if you substitute some garbage in the address bar with handles, the default sorting will work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question