Z
Z
zekin3752020-08-17 16:25:27
1C-Bitrix
zekin375, 2020-08-17 16:25:27

How to display bitrix infoblock elements to build a slider?

Please help me combine the code to display the slider

I get a list of elements

<?
if (CModule::IncludeModule("iblock")):
// ID инфоблока из которого выводим элементы
$iblock_id = 26;
$my_slider = CIBlockElement::GetList (
// Сортировка элементов
Array("ID" => "ASC"),
Array("IBLOCK_ID" => $iblock_id),
false,
false,
// Перечисляесм все свойства элементов, которые планируем выводить
Array(
'ID', 
'NAME', 
'PREVIEW_PICTURE', 
'PREVIEW_TEXT', 
'PROPERTY_LIN_PR'
)


Slider code

$limit = 10; // Amount of images to show
        $i = 0;
        $j = 0;

        foreach ( $result->data as $post )
        {
            if ( $i < $limit ){
                $i++;
                if(($i == 1) ||  ($i == 4)){?>
                    <div class="col-xs-12 col-sm-3 default">
                        <div class="image-wrapper">
                            <a href="<?=$link->link?>" target="_blank" class="image" style="background: url(<?=$img?>) no-repeat;"></a>
                        </div>
                    </div>
                <?}

                if($i == 2) {?>
                <div class="col-xs-12 col-sm-2 default">
                    <div class="row no-gutters h50">
                        <div class="col-xs-12 col-sm-12">
                            <div class="image-wrapper">
                                <a href="<?=$link->link?>" target="_blank" class="image" style="background: url(<?=$img?>) no-repeat;"></a>
                            </div>
                        </div>
                    </div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2020-08-17
@rpsv

What is the problem? The fact that there is no suitable ready-made code?

spoiler
foreach ($my_slider as $row) {
  $name = $row['NAME'];
  $previewSrc = $row['PREVIEW_PICTURE'] ? CFile::getPath($row['PREVIEW_PICTURE']) : null;
  $previewText = $row['PREVIEW_TEXT'];
  $linPrValue = $row['PROPERTY_LIN_PR_VALUE'];

  // code ...
}

V
Vyacheslav Klimov, 2020-08-18
@KlVV

Make it easier. you take the news list component and create your own template for it by copying and changing the default one. In $arResult in the template, you will already have all the pictures with ordering, taking into account sorting. js and css add to taste.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question