Answer the question
In order to leave comments, you need to log in
How to correctly display a multiple property with a condition?
Good time,
I display the multiple property file. a specific slider is used.
here is the layout, where the output of the property
<div class="swiper-slide">
<div class="news-slider__item">
<!-- вывод 1 картинки -->
<div class="news-slider__image-large">
<img src="img/slide1.jpg" width="" height="" alt="">
</div>
<!-- вывод остальных 3 картинок -->
<div class="news-slider__image-small">
<img src="img/slide2.jpg" width="" height="" alt=" title="">
<img src="img/slide3.jpg" width="" height="" alt="" title="">
<img src="img/slide4.jpg" width="" height="" alt="" title="">
</div>
</div>
</div>
<?if($arResult['GALLERY_PHOTOS']) { //проверка на картинки?>
<?
$count = 0;
foreach ($arResult['GALLERY_PHOTOS'] as $key => $photo) {
$count++;
?>
<div class="swiper-slide">
<div class="news-slider__item">
<?if($count == 1):?>
<div class="news-slider__image-large">
<img src="<?=$photo['SRC_BIG'];?>" alt="<?=$photo['ALT'];?>" title="<?=$photo['TITLE'];?>">
</div>
<?endif;?>
<div class="news-slider__image-small">
<img src="<?=$photo['SRC_SMALL'];?>" alt="<?=$photo['ALT'];?>">
</div>
</div>
</div>
<?}?>
<?}?>
Answer the question
In order to leave comments, you need to log in
To display the first image as a div, you don’t need any special tricks:
<div class="news-slider__image-large">
<img src="<?=$arResult['GALLERY_PHOTOS'][0]['SRC_BIG'];?>" alt="<?=$arResult['GALLERY_PHOTOS'][0]['ALT'];?>" title="<?=$arResult['GALLERY_PHOTOS'][0]['TITLE'];?>">
</div>
<div class="news-slider__image-small">
<?for ($i = 1; $i < count($arResult['GALLERY_PHOTOS']); $i++):?>
<img src="<?=$arResult['GALLERY_PHOTOS'][$i]['SRC_SMALL'];?>" alt="<?=$arResult['GALLERY_PHOTOS'][$i]['ALT'];?>">
<?endfor;?>
</div>
All the rules, output. It remains to transfer the image from small photos to a large block.
At the moment, according to the indicated solution,
there is 1 photo in the large block and 3 small photos in another block,
but scrolling through, 1 photo remains in the large block, how to pass the parameter so that the 2nd photo goes to the large block?
Now the output loop looks like this:
<div class="swiper-wrapper">
<?if($arResult['GALLERY_PHOTOS']) { ?>
<?foreach ($arResult['GALLERY_PHOTOS'] as $key => $photo) { ?>
<div class="swiper-slide">
<div class="news-slider__item">
<div class="news-slider__image-large">
<img src="<?=$arResult['GALLERY_PHOTOS'][0]['SRC_BIG'];?>" alt="<?=$arResult['GALLERY_PHOTOS'][0]['ALT'];?>" title="<?=$arResult['GALLERY_PHOTOS'][0]['TITLE'];?>">
</div>
<div class="news-slider__image-small">
<?for ($i = 1; $i < count($arResult['GALLERY_PHOTOS']); $i++):?>
<img src="<?=$arResult['GALLERY_PHOTOS'][$i]['SRC'];?>" alt="<?=$arResult['GALLERY_PHOTOS'][$i]['ALT'];?>">
<?endfor;?>
</div>
</div>
</div>
<?}?>
<?}?>
</div>
<div class="swiper-pagination"></div>
<div class="news-slider__btn next-slide">Далее <svg class="icon" width="16" height="16"><use xlink:href="/img/icons/icon-sprite.svg#icon-right-arrow"></use></svg></div>
<div class="news-slider__btn prev-slide"><svg class="icon" width="16" height="16"><use xlink:href="/img/icons/icon-sprite.svg#icon-left-arrow"></use></svg> Назад</div>
<?for ($i = 1; $i < count($arResult['GALLERY_PHOTOS']); $i++):?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question