A
A
adap2019-03-04 22:44:05
1C-Bitrix
adap, 2019-03-04 22:44:05

How to make SEO data for a smart filter?

There is a smart filter and static pages from it, you need to give them unique meta tags and text.
I've seen a lot of questions on this topic, but I didn't find a solution.
The closest is stated here https://it-svalka.ru/razrabotka/tonkaya-nastroyka-... (and found a few copy-pastes). Although the presentation here is not very good for "noobs", for example, an example of assigning an infoblock constant in the /bitrix/php_interface/init.php file is not shown (but I sort of figured it out), there is no example of the element code when creating infoblocks (also seems to be done) and the most important , what you are stuck on, where and how to insert the proposed code into section.php so that it works.
How did not try or the directory breaks or is ignored. The infoblock element is, of course, already set for verification.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
adap, 2019-03-09
@adap

So the solution for which I paid money (it's good that it's not big) and which works:

$currentPageUrl = $APPLICATION->GetCurPage(false);
$currentPageSeo = array();
$arSelect = Array("ID", "PROPERTY_TITLE", "PROPERTY_META_KEYWORDS", "PROPERTY_META_DESCRIPTION", "PROPERTY_HEADER", "PROPERTY_SEO_TEXT");
$arFilter = Array("IBLOCK_ID"=>IBLOCK_SEO, "PROPERTY_PAGE_URL"=>$currentPageUrl);
$res = CIBlockElement::GetList(Array(), $arFilter, false, ["nTopCount" => 1], $arSelect);
if ($arItem = $res->GetNext()){
    $currentPageSeo = array(
            "TITLE" => $arItem["PROPERTY_TITLE_VALUE"],
            "KEYWORDS" => $arItem["PROPERTY_META_KEYWORDS_VALUE"],
            "DESCRIPTION" => $arItem["PROPERTY_META_DESCRIPTION_VALUE"],
            "HEADER" => $arItem["PROPERTY_HEADER_VALUE"],
            "SEO_TEXT" => $arItem["PROPERTY_SEO_TEXT_VALUE"]["TEXT"],
        );
}

Literally little change. Be sure to place the code in the active template, I placed it there - it could sometimes break the catalog output. I hope the code will be useful, and later I will try to add an article about this on my website, hoping to kill a lot of paid solutions in this regard in the issuance.
It will be strange to mark your own answer as the answer to the question, but it works.

V
Vitaly, 2019-03-06
@vcherepko

In init.php
define( 'IBLOCK_SEO', 'ID_Your created infoblock' ); //lobo just in $arFilter
In section.php at the end

$currentPageUrl = str_replace(' ','%20',$APPLICATION->GetCurPage(false)); //мне пришлось экранировать пробелы
  $currentPageSeo = array();
  $arSelect = Array("ID", "PROPERTY_SEO_TITLE", "PROPERTY_SEO_KEYWORDS", "PROPERTY_SEO_DESCRIPTION");
  $arFilter = Array("IBLOCK_ID"=>IBLOCK_SEO, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y", "PROPERTY_SEO_URL"=>$currentPageUrl);
  $res = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
  while($ob = $res->GetNextElement()){
      $arFields = $ob->GetFields();
      $currentPageSeo = array(
        "TITLE" => $arFields["PROPERTY_SEO_TITLE_VALUE"],
        "KEYWORDS" => $arFields["PROPERTY_SEO_KEYWORDS_VALUE"],
        "DESCRIPTION" => $arFields["PROPERTY_SEO_DESCRIPTION_VALUE"]
    	);
  };

//Устанавливаем полученные параметры
  if($currentPageSeo["TITLE"]){
      $APPLICATION->SetPageProperty("title", $currentPageSeo["TITLE"]);
  }
  if($currentPageSeo["KEYWORDS"]){
      $APPLICATION->SetPageProperty("keywords", $currentPageSeo["KEYWORDS"]);
  }
  if($currentPageSeo["DESCRIPTION"]){
      $APPLICATION->SetPageProperty("description", strip_tags($cnt." ".$currentPageSeo["DESCRIPTION"]));
  };

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question