Answer the question
In order to leave comments, you need to log in
How to display additional images of an infoblock element through Bitrix API?
Hello! It is necessary to display additional images of the infoblock element using api bitrix. There are multiple properties like File ATT_OW_MORE_PHOTO
The code below outputs these images, but strangely, if there are three additional images. then it will display both the id and the name and the detailed text three times, how to rewrite it so that it is displayed normally:
<?
$iblock_id = 10;
$arSelect = Array("ID", "NAME", "PROPERTY_ATT_OW_MORE_PHOTO", "DETAIL_PICTURE", "DETAIL_TEXT");
$arFilter = Array( "IBLOCK_ID"=>$iblock_id, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y" );
$res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, false, false, $arSelect);
while($ob = $res->GetNextElement()) :
$arFields = $ob->GetFields();
echo "ID: " . $arFields['ID'];echo "<br>";
$db_old_groups = CIBlockElement::GetElementGroups($arFields['ID'], true);
// while($ar_group = $db_old_groups->Fetch())
// echo "SECTION CODE: " . $ar_group["CODE"]." ";
echo "<br>";
echo "NAME: " . $arFields['NAME'];echo "<br>";
echo "PICTURE: ".CFile::GetPath($arFields['DETAIL_PICTURE']);echo "<br>";
echo "DETAIL TEXT" . $arFields['DETAIL_TEXT'];echo "<br>";
echo "dop photo: ";
echo "<img src='" . CFile::GetPath($arFields['PROPERTY_ATT_OW_MORE_PHOTO_VALUE']) . "' />";
echo "<br>===================<br>";
endwhile;
?>
Answer the question
In order to leave comments, you need to log in
the getlist output should also contain additional properties in the form of an array ["PROPERTIES"]["ATT_OW_MORE_PHOTO"]
take it and run it through the loop
Decided like this:
<?
$iblock_id = 10;
$arSelect = Array("ID", "NAME", "CODE", "PROPERTY_ATT_OW_MORE_PHOTO", "DETAIL_PICTURE", "DETAIL_TEXT");
$arFilter = Array( "IBLOCK_ID"=>$iblock_id, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y" );
$res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, false, false, $arSelect);
$code = "";
while($ob = $res->GetNextElement()) :
$arFields = $ob->GetFields();
if ($code != $arFields['CODE']) {
$code = $arFields['CODE'];
echo "ID: " . $arFields['ID'];echo "<br>";
$db_old_groups = CIBlockElement::GetElementGroups($arFields['ID'], true);
while($ar_group = $db_old_groups->Fetch())
echo "SECTION CODE: " . $ar_group["CODE"]." ";
echo "<br>";
echo "NAME: " . $arFields['NAME'];echo "<br>";
echo "CODE: " . $arFields['CODE'];echo "<br>";
echo "PICTURE: "."<img width='250px' src='" . CFile::GetPath($arFields['DETAIL_PICTURE']) . "'/>";
echo "<br>";
echo "DETAIL TEXT: " . $arFields['DETAIL_TEXT'];echo "<br>";
}
echo "<img width='250px' src='" . CFile::GetPath($arFields['PROPERTY_ATT_OW_MORE_PHOTO_VALUE']) . "'/>";
endwhile;
unset($iblock_id, $arSelect, $arFilter, $res, $code, $ob, $arFields, $db_old_groups);
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question