JavaScript — 4 деления в Swiper Slide

У меня есть слайдер Swiper.

Мне нужно положить 4 деления на одном слайде и 2 деления на втором.

На первом слайде у меня есть 2 деления и 4 деления на втором.

function loadcontent() {
var id = $('.catslide>.swiper-wrapper>.swiper-slide-active').attr('data-id');
$.ajax({
type: "POST",
url: "../showthis.php",
data: {
id: id,
rand: 1
},
datatype: 'json',
success: function(data) {
var height = $('#slideadv').height();
$('#slideadv').height(height);
mySwiper.removeAllSlides();
mySwiper.appendSlide(data);
mySwiper.update();
}
});
}

//showthis.php //

$query3 =
"SELECT * FROM adv_items  WHERE category_id='$id' AND adv_type='Standard' AND hide='show' ORDER BY RAND()";
$advst = $db - > prepare($query3);
$advst - > fetchAll(PDO::FETCH_ASSOC);
$advst - > execute();
$text = '';foreach(array_chunk($advst - > fetchAll(), 4, true) as $advsts) {
{
echo '<div class="swiper-slide">';
foreach($advsts as $kicks) {
echo '<div class="col-md-6 advertising">';
echo '<div class="company-logo"><img src="./'.$kicks['clogo'].
'" alt="..."></div>';
echo '<div class="company-contcs"><p class="company-title">'.$kicks[
'cname'].
'</p><a href="tel:'.$kicks['phone1'].
'">Телефон: '.$kicks['phone1'].
'</a><a href="'.$kicks['curl'].
'">'.$kicks['curl'].
'</a></div>';
echo '<p class="company-desc">'.substr($kicks['text'], 0, 600).
'</p>';
echo "</div>";
}
echo '</div>';
}
}

// mypage.php //

$query3 =
"SELECT * FROM adv_items  WHERE category_id='$id' AND adv_type='Standard' AND hide='show' ORDER BY RAND()";
$advst = $db - > prepare($query3);
$advst - > fetchAll(PDO::FETCH_ASSOC);
$advst - > execute();
$text = '';

foreach(array_chunk($advst - > fetchAll(), 4, true) as $advsts) {
{
echo '<div class="swiper-slide">';
foreach($advsts as $kicks) {
echo '<div class="col-md-6 advertising">';
echo '<div class="company-logo"><img src="./'.$kicks['clogo'].
'" alt="..."></div>';
echo '<div class="company-contcs"><p class="company-title">'.$kicks[
'cname'].
'</p><a href="tel:'.$kicks['phone1'].
'">Телефон: '.$kicks['phone1'].
'</a><a href="'.$kicks['curl'].
'">'.$kicks['curl'].
'</a></div>';
echo '<p class="company-desc">'.substr($kicks['text'], 0, 600).
'</p>';
echo "</div>";
}
echo '</div>';
}
}

// mypage.php //

<div id = "webslider" class = "row webslider">
<div class = "container">
<div class = "swiper-container categories-advertising">
<!-- Additional required wrapper -->
<div id = "slideadv" class = "swiper-wrapper slideadv">
<?php
foreach (array_chunk($advst->fetchAll(), 4, true) as $advsts) {
{
echo '<div class="swiper-slide">';
foreach ($advsts as $kicks) {
?>
<div class = "col-md-6 advertising">
<div class = "company-logo">
<img src = "./<?php echo $kicks['clogo'] ?>" alt = "...">
</div>
<div class = "company-contcs">
<p class = "company-title">
<?php
echo $kicks['cname']
?>
</p>
<a href = "tel:<?php echo $kicks['phone1'] ?>"> Телефон:
<?php
echo $kicks['phone1']
?>
</a>
<a href = "<?php echo $kicks['curl'] ?>">
<?php
echo $kicks['curl']
?>
</a>
</div>
<p class = "company-desc">
<?php
echo substr($kicks['text'], 0, 600)
?>
</p>
</div>
<?php
}
echo '</div>';
}
?>
<?php
}
?>
</div>
<div class = "swiper-button-next">
<img width = "30px" src = "./img/scroll-arrow-right.svg" alt = "arrow right">
</div>
<div class = "swiper-button-prev">
<img width = "30px" src = "./img/scroll-arrow-left.svg" alt = "arrow left">
</div>
</div>
</div>
</div>

Я использую JavaScript для обновления этого слайдера.

0

Решение

Я нахожу решение без array_chunk, я использую slidesPerColumn а также slidesPerGroup в моем слайдере. Вот код:

//define swiper//

var mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal',
slidesPerView: '2',
slidesPerColumn: '2',
spaceBetween: 0,
slidesPerGroup: '1',
slidesPerColumnFill: 'column',
touchRatio: '2',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev'
});

mypage.php

<div class="swiper-container categories-advertising">
<!-- Additional required wrapper -->
<div id="slideadv" class="swiper-wrapper slideadv">
<?php foreach ($advst->fetchAll() as $kicks) { ?>
<div class="swiper-slide">
<div class="col-md-12 advertising">
<div class="company-logo">
<img src="./<?php echo $kicks['clogo'] ?>" alt="...">
</div>
<div class="company-contcs">
<p class="company-title"><?php echo $kicks['cname'] ?></p>
<a href="tel:<?php echo $kicks['phone1'] ?>">Телефон: <?php echo $kicks['phone1'] ?></a>
<a href="<?php echo $kicks['curl'] ?>"><?php echo $kicks['curl'] ?></a>
</div>
<p class="company-desc">
<?php echo substr($kicks['text'], 0, 600) ?>
</p>
</div>
</div>
<?php }?>
</div>
<div class="swiper-button-next"><img width="30px" src="./img/scroll-arrow-right.svg" alt="arrow right">
</div>
<div class="swiper-button-prev"><img width="30px" src="./img/scroll-arrow-left.svg" alt="arrow left">
</div>
</div>

showthis.php это для ответа AJAX

$query3 = "SELECT * FROM adv_items  WHERE category_id='$id' AND adv_type='STANDARD' AND hide='show' ORDER BY RAND()";
$advst = $db->prepare($query3);
$advst->fetchAll(PDO::FETCH_ASSOC);
$advst->execute();

foreach ($advst->fetchAll() as $kicks)
{
echo '<div class="swiper-slide">';
echo '<div class="col-md-12 advertising">';
echo '<div class="company-logo"><img src="./' . $kicks['clogo'] . '" alt="..."></div>';
echo '<div class="company-contcs"><p class="company-title">' . $kicks['cname'] . '</p><a href="tel:' . $kicks['phone1'] . '">Phone: ' . $kicks['phone1'] . '</a><a href="' . $kicks['curl'] . '">' . $kicks['curl'] . '</a></div>';
echo '<p class="company-desc">' . substr($kicks['text'], 0, 600) . '</p>';
echo "</div>";
echo '</div>';
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]