U
U
UNiT LAB2020-04-20 13:48:05
1C-Bitrix
UNiT LAB, 2020-04-20 13:48:05

How to disable the output of subsection elements in 1C Bitrix?

Please tell me...
There is a site page that displays a list of elements from sections and subsections.
The filter shows sections by which elements can be filtered.
How to make it so that the filter does not show nested elements from under sections, but only from the section in which you are located?
That is, the main Services section should not display elements of subsections Services / Subsection 1, etc.
A should only show elements from the Services section

5e9d7c8e0ac85646335967.png

<b>result_modifier.php</b>
<?
if($arParams["DISPLAY_SECTION_FILTER"] === "Y") {
  $arResult["SECTIONS"] = array();
  $arResult["IS_ALL"] = true;
  $arOrder = array("NAME"=>"ASC");
  $arFilter = array("ACTIVE" => "Y", "IBLOCK_ID" => 2 );
  $arSelect = array("NAME", "CODE", 'SECTION_PAGE_URL');
  $arNavParams = array('nTopCount' => 20);
  $rsSection = CIBlockSection::GetList($arOrder,$arFilter,false,$arSelect,$arNavParams);
  while($arSection = $rsSection->GetNext())
  {	
    if($arSection['CODE'] === $_REQUEST['SECTION_CODE']) {
      $arResult["IS_ALL"] = false;
      $arSection["ACTIVE"] = true;
    }
    $arResult["SECTIONS"][] = $arSection;
  }
}

foreach ($arResult['ITEMS'] as &$arItem) {
  $arItem['IMAGE'] = CFile::ResizeImageGet($arItem['PREVIEW_PICTURE']['ID'], array('width'=>370, 'height'=>370), BX_RESIZE_IMAGE_EXACT);
}
$arResult['IS_SHOW_MORE'] = !!($arResult["NAV_RESULT"]->NavPageCount - $arResult["NAV_RESULT"]->NavPageNomer);


<b>template.php</b>
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @global CDatabase $DB */
/** @var CBitrixComponentTemplate $this */
/** @var string $templateName */
/** @var string $templateFile */
/** @var string $templateFolder */
/** @var string $componentPath */
/** @var CBitrixComponent $component */
$this->setFrameMode(true);
if(!empty($arResult['ITEMS'])):
?>


<div class="row services-list" data-news_count="<?=$arParams['NEWS_COUNT']?>">

  <?if(!empty($arResult["SECTIONS"])):?>
  
    <div class='col-xs-12'>
      <div class='filter hr'>
        <span>Вид услуг:</span>
        <a <?if(!empty($arResult['IS_ALL'])):?> class="active"<?endif;?> data-section='' href="<?=$arResult['ITEMS'][0]["LIST_PAGE_URL"]?>">Все</a>
        <?foreach($arResult['SECTIONS'] as $arSection):?>
          <a <?if(!empty($arSection['ACTIVE'])):?> class="active"<?endif;?> data-section='<?=$arSection['CODE']?>' href="<?=$arSection['SECTION_PAGE_URL']?>"><?=$arSection['NAME']?></a>
        <?endforeach;?>
      </div>
    </div>
  
  <?endif;?>
  
  <div class='js-items-wrap'>
  
    <div class='js-items'>
    
      <?foreach ($arResult['ITEMS'] as $key => $arItem):?>
      <?
      $this->AddEditAction($arItem['ID'], $arItem['EDIT_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_EDIT"));
      $this->AddDeleteAction($arItem['ID'], $arItem['DELETE_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BNL_ELEMENT_DELETE_CONFIRM')));
      ?>		
        <div class='col-lg-4 col-sm-6 col-xs-12 svItem-item' id="<?=$this->GetEditAreaId($arItem['ID']);?>">
          
          <a href="<?=$arItem["DETAIL_PAGE_URL"]?>" class="svItem-item-wrapper angle">
        
                  <div class='table'>
                  
                    <div class="svItem-picture text-center td-center">
                    
                      <img src="<?=$arItem['PREVIEW_PICTURE']['SRC'] ?>" alt="<?=$arItem['NAME'] ?>" />	
                      
                    </div> 
                  
                  </div>
                  

              
                  <h5 class='text-center text-uppercase'><?=$arItem["NAME"]?></h5>
                  
                  <div class='text-center desc'><?=$arItem["PREVIEW_TEXT"]?></div>
            
          </a>
          

          
        </div>

      <?endforeach;?>
      
      <div class='clearfix'></div>
      
      <?if($arResult["IS_SHOW_MORE"]):?>
      
        <div class='show_more_wrap'>
        
          <button class='show_more' data-page='<?=$_REQUEST['PAGEN_1']?>' data-section='<?=$_REQUEST['SECTION_CODE']?>'>Ещё</button>
        
        </div>
      
      <?endif;?>
    
    </div>
    
  </div>
  
</div>

<?endif;?>


<b>script.js</b>
$(document).ready(function(){
  
  $(document).on('click','.services-list .show_more:not(.loading)', function(){
    var $this = $(this);
    var $wrap = $this.closest('.services-list');
    var page = +$this.data('page')||1;
    var $wrapItems = $wrap.find('.js-items-wrap');
    $this.addClass('loading').text('Загрузка...');
    
    var data = {
      'PAGEN_1':page+1,
      'SECTION_CODE':$this.data('section'),
      'NEWS_COUNT' :$wrap.data('news_count')
    }
    $.get('/local/include/ajax/services/show_more.php', data, function(html){
      $this.remove();
      $wrapItems.append($(html).find('.js-items').html());
    })
  })
  $('.services-list .filter a').on('click', function(e){
    e.preventDefault();
    var $a = $(this);
    var $filter = $a.parent('.filter');
    
    var $wrap = $a.closest('.services-list');
    var $wrapItems = $wrap.find('.js-items-wrap');
    history.pushState(null, null, this.href); 
    var data = {
      'PAGEN_1':1,
      'SECTION_CODE': $a.attr('href').split('/')[2],
      'NEWS_COUNT' : $wrap.data('news_count')
    }

    $wrapItems.load('/local/include/ajax/services/show_more.php .js-items', data, function(data){
      $filter.find('a').removeClass('active');
      $a.addClass('active');
    });
    
  })
  $(window).on('popstate', function(e) {
    var $wrap = $('.services-list');
    var $wrapItems = $wrap.find('.js-items-wrap');
    var $filter_a = $wrap.find('.filter a');
    var section = location.pathname.split('/')[2]
    console.log(location);
    var data = {
      'PAGEN_1':1,
      'SECTION_CODE': section,
      'NEWS_COUNT' : $wrap.data('news_count')
    }
    $wrapItems.load('/local/include/ajax/services/show_more.php .js-items', data, function(data){
      $filter_a.removeClass('active');
      $filter_a.filter('[data-section="'+section+'"]').addClass('active');
    });
    })
});


<b>.parameters.php</b>
<?
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();

$arTemplateParameters = array(
  "DISPLAY_DATE" => Array(
    "NAME" => GetMessage("T_IBLOCK_DESC_NEWS_DATE"),
    "TYPE" => "CHECKBOX",
    "DEFAULT" => "Y",
  ),
  "DISPLAY_NAME" => Array(
    "NAME" => GetMessage("T_IBLOCK_DESC_NEWS_NAME"),
    "TYPE" => "CHECKBOX",
    "DEFAULT" => "Y",
  ),
  "DISPLAY_PICTURE" => Array(
    "NAME" => GetMessage("T_IBLOCK_DESC_NEWS_PICTURE"),
    "TYPE" => "CHECKBOX",
    "DEFAULT" => "Y",
  ),
  "DISPLAY_PREVIEW_TEXT" => Array(
    "NAME" => GetMessage("T_IBLOCK_DESC_NEWS_TEXT"),
    "TYPE" => "CHECKBOX",
    "DEFAULT" => "Y",
  ),
  "DISPLAY_SECTION_FILTER" => Array(
    "NAME" => GetMessage("DISPLAY_SECTION_FILTER"),
    "TYPE" => "CHECKBOX",
    "DEFAULT" => "Y",
  ),
);
?>


<b>index.php</b>
<?if(!empty($_REQUEST['SECTION_CODE'])) {
  $arFilter = array('SECTION_CODE' => $_REQUEST['SECTION_CODE']);
}?>
<?$APPLICATION->IncludeComponent(
  "bitrix:news.list", 
  "services", 
  array(
    "ACTIVE_DATE_FORMAT" => "d.m.Y",
    "ADD_SECTIONS_CHAIN" => "Y",
    "AJAX_MODE" => "N",
    "AJAX_OPTION_ADDITIONAL" => "",
    "AJAX_OPTION_HISTORY" => "N",
    "AJAX_OPTION_JUMP" => "N",
    "AJAX_OPTION_STYLE" => "Y",
    "CACHE_FILTER" => "N",
    "CACHE_GROUPS" => "Y",
    "CACHE_TIME" => "36000000",
    "CACHE_TYPE" => "A",
    "CHECK_DATES" => "Y",
    "DETAIL_URL" => "",
    "DISPLAY_BOTTOM_PAGER" => "Y",
    "DISPLAY_DATE" => "Y",
    "DISPLAY_NAME" => "Y",
    "DISPLAY_PICTURE" => "Y",
    "DISPLAY_PREVIEW_TEXT" => "Y",
    "DISPLAY_SECTION_FILTER" => "Y",
    "DISPLAY_TOP_PAGER" => "N",
    "FIELD_CODE" => array(
      0 => "",
      1 => "",
    ),
    "FILTER_NAME" => "arFilter",
    "HIDE_LINK_WHEN_NO_DETAIL" => "N",
    "IBLOCK_ID" => "2",
    "IBLOCK_TYPE" => "catalog",
    "INCLUDE_IBLOCK_INTO_CHAIN" => "N",
    "INCLUDE_SUBSECTIONS" => "Y",
    "MESSAGE_404" => "",
    "NEWS_COUNT" => "12",
    "PAGER_BASE_LINK_ENABLE" => "N",
    "PAGER_DESC_NUMBERING" => "N",
    "PAGER_DESC_NUMBERING_CACHE_TIME" => "36000",
    "PAGER_SHOW_ALL" => "N",
    "PAGER_SHOW_ALWAYS" => "N",
    "PAGER_TEMPLATE" => ".default",
    "PAGER_TITLE" => "Новости",
    "PARENT_SECTION" => "",
    "PARENT_SECTION_CODE" => "",
    "PREVIEW_TRUNCATE_LEN" => "",
    "PROPERTY_CODE" => array(
      0 => "",
      1 => "",
    ),
    "SET_BROWSER_TITLE" => "Y",
    "SET_LAST_MODIFIED" => "N",
    "SET_META_DESCRIPTION" => "Y",
    "SET_META_KEYWORDS" => "Y",
    "SET_STATUS_404" => "N",
    "SET_TITLE" => "Y",
    "SHOW_404" => "N",
    "SORT_BY1" => "ACTIVE_FROM",
    "SORT_BY2" => "SORT",
    "SORT_ORDER1" => "DESC",
    "SORT_ORDER2" => "ASC",
    "COMPONENT_TEMPLATE" => "services",
    "STRICT_SECTION_CHECK" => "N"
  ),
  false
);?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-04-21
@rpsv

Look towards the FILTER_NAME parameter to set filtering: https://dev.1c-bitrix.ru/user_help/components/cont...
-
By default, subcategory elements are not searched if it is not set in the INCLUDE_SUBSECTIONS filter, check the filter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question