A
A
Askfortrue2021-10-31 15:31:11
1C-Bitrix
Askfortrue, 2021-10-31 15:31:11

How to properly sort in the News component?

Good afternoon!
Tell me, does the sorting setting in the News component differ from the Catalog component in any way?
Everything in the catalog is without problems, in the News I can’t understand, it doesn’t work.
I read about Sorting here , but it does not come out yet. Sort ordinary elements.

In more detail what I did:
1. Put the code in section.php

<?if (
    isset($_GET["sort"]) && isset($_GET["method"]) && (
$_GET["sort"] == "name" || 
              $_GET["sort"] == "catalog_PRICE_3" ||
             $_GET["sort"] == "property_PRODUCT_TYPE" ||
             $_GET["sort"] == "timestamp_x")){
       $arParams["ELEMENT_SORT_FIELD"] = $_GET["sort"];
       $arParams["ELEMENT_SORT_ORDER"] = $_GET["method"];
   }?>

2. posted this code in news_list
<p class="sort">Сортировка:
    <a <?if ($_GET["sort"] == "name"):?> class="active" <?endif;?>
       href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=name&method=asc">название</a> 
    <a <?if ($_GET["sort"] == "catalog_PRICE_3"):?> class="active" <?endif;?>
       href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=catalog_PRICE_3&method=asc">цена</a> 
    <a <?if ($_GET["sort"] == "property_PRODUCT_TYPE"):?> class="active" <?endif;?>
       href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=property_PRODUCT_TYPE&method=desc">лидер продаж</a> 
    <a <?if ($_GET["sort"] == "timestamp_x"):?> class="active" <?endif;?>
       href="<?=$arResult["SECTION_PAGE_URL"]?>?sort=timestamp_x&method=desc">дата поступления</a>
</p>

Set up the required fields.
As if everything is very simple, but it does not plow.
Tell me

Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-10-31
@PetrPo

The parameters are named differently than ELEMENT_SORT_FIELD and ELEMENT_SORT_ORDER. Look in the documentation for the news component

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question