Answer the question
In order to leave comments, you need to log in
How to create an xml sitemap for images?
Tell me how to make a sitemap for images for a site on CMS 1C-Bitrix?
The sitemap for images should be of the following format: https://support.google.com/webmasters/answer/17863...
In Bitrix there is an opportunity to create a regular sitemap, there seems to be no such possibility, but an xml map for an image cannot be created there. Online generators also do not create an xml map for a site on Bitrix.
Can you recommend the c marketplace module?
Answer the question
In order to leave comments, you need to log in
I sketched out the code for you.
<?
require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("iblock");
$dom = new domDocument("1.0", 'utf-8');
$xml = $dom->createElement("xml");
$xml ->setAttributeNS(null, 'version', '1.0');
$xml ->setAttributeNS(null, 'encoding', 'utf-8');
$dom->appendChild($xml);
$urlset = $dom->createElement("urlset");
$urlset->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
$urlset->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:image','http://www.google.com/schemas/sitemap-image/1.1');
$arSelect = Array("ID", "NAME", "DETAIL_PAGE_URL", "PREVIEW_PICTURE");
$arFilter = Array("IBLOCK_ID"=>8, "SECTION_ID"=>100, "INCLUDE_SUBSECTIONS" => "Y"); //ID Инфоблока и ID раздела с элементами
$rsElement = CIBlockElement::GetList(Array("NAME" => "ASC"), $arFilter, false, Array("nPageSize"=>5), $arSelect);
$arResult["ITEMS"] = array();
while($obElement = $rsElement->GetNextElement())
{
$arItem = $obElement->GetFields();
$arItem["PROPERTIES"] = $obElement->GetProperties();
$google_link = 'https://site.ru'.$arItem[DETAIL_PAGE_URL];
$google_img = 'https://site.ru'.CFile::GetPath($arItem[PREVIEW_PICTURE]);
$url = $dom->createElement("url");
$login = $dom->createElement("loc", $google_link);
$url->appendChild($login);
$image = $dom->createElement("image:image");
$image2 = $dom->createElement("image:loc", $google_img);
$image->appendChild($image2);
$url->appendChild($image);
$urlset->appendChild($url);
};
$xml->appendChild($urlset);
$dom->save("img.xml"); //в корне директории откуда запускаем скрипт
echo 'Готово';
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question