Owl carousel cloned issue with php - php

My issue is owl carousel clone the item
i started with getting Reviews
<?php
if($total_num_of_rev > 0) { ?>
<div class="row">
<?php
$numOfCols = 6;
$rowCount = 0;
foreach($review_list_data as $key => $review_data) { ?>
and i put them in html code as following:
<div class="row">
<?php
if($total_num_of_rev > 0) { ?>
<div class="row">
<?php
$numOfCols = 6;
$rowCount = 0;
foreach($review_list_data as $key => $review_data) { ?>
<div class="col-md-12">
<div class="owl-carousel-3col" data-dots="false">
<div class="item">
<div class="testimonial style1">
<div class="comment bg-theme-colored">
<p class="font-15 pl-0 text-white"><?=$review_data['content']?></p>
</div>
<div class="thumb content mt-10 mb-10">
<?php
if($review_data['photo']) { ?>
<img class="img-circle" alt="" src="<?=SITE_URL.'images/review/'.$review_data['photo']?>">
<?php
} else { ?>
<img src="images/placeholder_avatar.jpg">
<?php
} ?>
</div>
<h4 class="author text-white mt-0 mb-0"><?=$review_data['name'].$i?></h4>
<h6 class="title text-white mt-0 mb-15">Designer</h6>
</div>
</div>
</div>
<div class="row"></div>
</div>
<?php
$rowCount++;
} ?>
<?php
} ?>
</div>
A screenshot of the issue
<section class="divide" data-bg-img="images/bg/bg8.jpg" style="background: 50% 97px rgb(17, 17, 17);">
<div class="container pt-60 pb-60">
<div class="section-title text-center">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h2 class="text-uppercase text-white line-bottom-center mt-0">What Claint's <span class="text-theme-colored2">Say</span></h2>
<div class="title-flaticon">
<i class="flaticon-charity-alms"></i>
</div>
<p class="text-white">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem autem<br> voluptatem obcaecati!</p>
</div>
</div>
</div>
<div class="row">
<?php
if($total_num_of_rev > 0) { ?>
<div class="row">
<?php
$numOfCols = 6;
$rowCount = 0;
foreach($review_list_data as $key => $review_data) { ?>
<div class="col-md-12">
<div class="owl-carousel-3col" data-dots="false">
<div class="item">
<div class="testimonial style1">
<div class="comment bg-theme-colored">
<p class="font-15 pl-0 text-white"><?=$review_data['content']?></p>
</div>
<div class="thumb content mt-10 mb-10">
<?php
if($review_data['photo']) { ?>
<img class="img-circle" alt="" src="<?=SITE_URL.'images/review/'.$review_data['photo']?>">
<?php
} else { ?>
<img src="images/placeholder_avatar.jpg">
<?php
} ?>
</div>
<h4 class="author text-white mt-0 mb-0"><?=$review_data['name'].$i?></h4>
<h6 class="title text-white mt-0 mb-15">Designer</h6>
</div>
</div>
</div>
<div class="row"></div>
</div>
</div>
<h4 class="author text-white mt-0 mb-0"><?=$review_data['name'].$i?></h4>
<h6 class="title text-white mt-0 mb-15">Designer</h6>
</div>
</div>
</div>
<div class="row"></div>
</div>
<?php
$rowCount++;
} ?>
<?php
} ?>
</div>
</section>
I think i have mistake in javascript but not sure :
var $owl_carousel_3col = $('.owl-carousel-3col');
if ( $owl_carousel_3col.length > 0 ) {
if(!$owl_carousel_3col.hasClass("owl-carousel")){
$owl_carousel_3col.addClass("owl-carousel owl-theme");
}
$owl_carousel_3col.each(function() {
var data_dots = ( $(this).data("dots") === undefined ) ? false: $(this).data("dots");
var data_nav = ( $(this).data("nav")=== undefined ) ? false: $(this).data("nav");
var data_duration = ( $(this).data("duration") === undefined ) ? 4000: $(this).data("duration");
$(this).owlCarousel({
rtl: THEMEMASCOT.isRTL.check(),
autoplay: true,
autoplayTimeout: data_duration,
loop: false,
rewind: true,
items: 6,
margin: 15,
dots: data_dots,
nav: data_nav,
navText: [
'<i class="fa fa-chevron-left"></i>',
'<i class="fa fa-chevron-right"></i>'
],
responsive: {
0: {
items: 1,
center: false
},
480: {
items: 1,
center: false
},
600: {
items: 1,
center: false
},
750: {
items: 2,
center: false
},
960: {
items: 2
},
1170: {
items: 3
},
1300: {
items: 3
}
}
});
});
}

Your problem seems to be the position of your foreach loop. You want to loop the item, not the whole column.
Basically you are creating an carousel for each of your reviews and owl fills the whole width of your container with clones of the item.
Put your foreach loop around
<div class="item">
and try again.

i put foreach before item
one the following code :
<div class="row">
<div class="col-md-12">
<div class="owl-carousel-5col" data-dots="false">
<?php
if($total_num_of_rev > 0) { ?>
<div class="row">
<?php
$numOfCols = 6;
$rowCount = 0;
foreach($review_list_data as $key => $review_data) { ?>
<div class="item">
<div class="testimonial style1">
<div class="comment bg-theme-colored">
<p class="font-15 pl-0 text-white"><?=$review_data['content']?></p>
</div>
<div class="thumb content mt-10 mb-10">
<?php
if($review_data['photo']) { ?>
<img class="img-circle" alt="" src="<?=SITE_URL.'images/review/'.$review_data['photo']?>">
<?php
} else { ?>
<img src="images/placeholder_avatar.jpg">
<?php
} ?>
</div>
<h4 class="author text-white mt-0 mb-0"><?=$review_data['name'].$i?></h4>
<h6 class="title text-white mt-0 mb-15">Designer</h6>
</div>
</div>
</div>
<?php
$rowCount++;
} ?>
<?php
} ?>
</div>
</div>
</div>
but still an issue there
screenshot

i manage to fix the issue
To fix it i needed to put a div inside the loop
but it seems there is an empty item between every loop finish
<section class="divide" data-bg-img="images/bg/bg8.jpg" style="background: 50% 97px rgb(17, 17, 17);">
<div class="container pt-60 pb-60">
<div class="section-title text-center">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h2 class="text-uppercase text-white line-bottom-center mt-0">What Claint's <span class="text-theme-colored2">Say</span></h2>
<div class="title-flaticon">
<i class="flaticon-charity-alms"></i>
</div>
<p class="text-white">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem autem<br> voluptatem obcaecati!</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="owl-carousel-3col" data-dots="">
<?php
if($total_num_of_rev > 0) { ?>
<div class="">
<?php
$numOfCols = 3;
$rowCount = 0;
foreach($review_list_data as $key => $review_data) { ?>
<div class="item">
<div class="testimonial style1">
<div class="comment bg-theme-colored">
<p class="font-15 pl-0 text-white"><?=$review_data['content']?></p>
</div>
<div class="thumb content mt-10 mb-10">
<?php
if($review_data['photo']) { ?>
<img class="img-circle" alt="" src="<?=SITE_URL.'images/review/'.$review_data['photo']?>">
<?php
} else { ?>
<img src="images/placeholder_avatar.jpg">
<?php
} ?>
</div>
<h4 class="author text-white mt-0 mb-0"><?=$review_data['name'].$i?></h4>
<h6 class="title text-white mt-0 mb-15">Designer</h6>
</div>
</div>
</div>
<div class="">
<?php
$rowCount++;
} ?>
<?php
} ?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
this is how it look
Screenshot 1
screenshot 2
any help?

Related

Divs below another with bootstrap 5 and not going to side

I'm trying to align a div like a gallery through a loop,
is there a way to do this efficiently with bootstrap? they just stay one above another. I tried to make more divs, but they repeat the results of first too. I'm using Laravel 9.0 and Bootstrap 5.0
#extends('master')
<body class="bg-light"></body>
<div class="container-fluid">
<div class="px-lg-5">
<?php
if (!empty($sql)) {
foreach ($sql as $value) {
?>
<div class="row">
<!-- Gallery item -->
<div class="col-xl-3 col-lg-4 col-md-6 mb-4 float-left">
<div class="bg-white rounded shadow-sm"><img src="https://bootstrapious.com/i/snippets/sn-gallery/img-1.jpg" alt="" class="img-fluid card-img-top">
<div class="p-4">
<h5> <?php echo $value->name; ?></h5>
<p class="small text-muted mb-0">Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
<p class="small text-muted mb-0">Avaliable: <?php echo $value->quantity ?></p>
<div class="d-flex align-items-center justify-content-between rounded-pill bg-light px-3 py-2 mt-4">
<p class="small mb-0"><span class="font-weight-bold">R$<?php echo $value->price ?></span></p>
<div class="badge badge-danger px-3 rounded-pill font-weight-normal">
<span class="text-dark"><?php echo substr($value->category, 0, 7); ?></span>
</div>
<div>
GET
</div>
<div>
GET
</div>
</div>
</div>
</div>
</div>
<!-- End -->
<?php } ?>
<!-- End -->
<?php } ?>
</div>
<div class="py-5 text-right">Show me more</div>
</div>
</div>
</body>
seeing the code shows you are creating more rows with the foreach. try this code that i provided whether it will solve your issues
<div class="container-fluid"><div class="px-lg-5">
<div class="row">
<?php if (!empty($sql)) {
foreach ($sql as $value) { ?>
<!-- Gallery item -->
<div class="col-xl-3 col-lg-4 col-md-6 mb-4 float-left">
<div class="bg-white rounded shadow-sm"><img src="https://bootstrapious.com/i/snippets/sn-gallery/img-1.jpg" alt="" class="img-fluid card-img-top">
<div class="p-4">
<h5> <?php echo $value->name; ?></h5>
<p class="small text-muted mb-0">Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
<p class="small text-muted mb-0">Avaliable: <?php echo $value->quantity; ?></p>
<div class="d-flex align-items-center justify-content-between rounded-pill bg-light px-3 py-2 mt-4">
<p class="small mb-0"><span class="font-weight-bold">R$<?php echo $value->price; ?></span></p>
<div class="badge badge-danger px-3 rounded-pill font-weight-normal">
<span class="text-dark"><?php echo substr(
$value->category,
0,
7
); ?></span>
</div>
<div>
GET
</div>
<div>
GET
</div>
</div>
</div>
</div>
</div>
<!-- End -->
<?php } ?>
<!-- End -->
<?php
} ?>
</div>
<div class="py-5 text-right">Show me more</div>
<div class="row"> shouldn't be in the foreach loop. Each item has a single row if you use it in the foreach loop.
Find:
<?php
if (!empty($sql)) {
foreach ($sql as $value) {
?>
<div class="row">
...
</div>
<?php
}
}
?>
Replace with:
<div class="row">
<?php
if (!empty($sql)) {
foreach ($sql as $value) {
?>
...
<?php
}
}
?>
</div>
In bootstap, row is a master container. col means grids inside the container.
egg:
<div class="row">
<div class="col-md-3">
item 1
</div>
<div class="col-md-3">
item 2
</div>
<div class="col-md-3">
item 3
</div>
<div class="col-md-3">
item 4
</div>
</div>
Please check here
link
Your mistake is to loop the main container.
#extends('master')
<body class="bg-light"></body>
<div class="container-fluid">
<div class="px-lg-5">
<div class="row">
<?php
if (!empty($sql)) {
foreach ($sql as $value) {
?>
<!-- Gallery item -->
<div class="col-xl-3 col-lg-4 col-md-6 mb-4 float-left">
<div class="bg-white rounded shadow-sm"><img src="https://bootstrapious.com/i/snippets/sn-gallery/img-1.jpg" alt="" class="img-fluid card-img-top">
<div class="p-4">
<h5> <?php echo $value->name; ?></h5>
<p class="small text-muted mb-0">Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
<p class="small text-muted mb-0">Avaliable: <?php echo $value->quantity ?></p>
<div class="d-flex align-items-center justify-content-between rounded-pill bg-light px-3 py-2 mt-4">
<p class="small mb-0"><span class="font-weight-bold">R$<?php echo $value->price ?></span></p>
<div class="badge badge-danger px-3 rounded-pill font-weight-normal">
<span class="text-dark"><?php echo substr($value->category, 0, 7); ?></span>
</div>
<div>
GET
</div>
<div>
GET
</div>
</div>
</div>
</div>
</div>
<!-- End -->
<?php } ?>
<!-- End -->
<?php } ?>
</div>
<div class="py-5 text-right">Show me more</div>
</div>
</div>
</body>
You had closed your body tag at 2nd line.
Try this:
#extends('master')
<body class="bg-light">
<div class="container-fluid">
<div class="px-lg-5">
<?php
if (!empty($sql)) {
foreach ($sql as $value) {
?>
<div class="d-flex">
<!-- Gallery item -->
<div class="col-xl-3 col-lg-4 col-md-6 mb-4 float-left">
<div class="bg-white rounded shadow-sm"><img src="https://bootstrapious.com/i/snippets/sn-gallery/img-1.jpg" alt="" class="img-fluid card-img-top">
<div class="p-4">
<h5> <?php echo $value->name; ?></h5>
<p class="small text-muted mb-0">Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
<p class="small text-muted mb-0">Avaliable: <?php echo $value->quantity ?></p>
<div class="d-flex align-items-center justify-content-between rounded-pill bg-light px-3 py-2 mt-4">
<p class="small mb-0"><span class="font-weight-bold">R$<?php echo $value->price ?></span></p>
<div class="badge badge-danger px-3 rounded-pill font-weight-normal">
<span class="text-dark"><?php echo substr($value->category, 0, 7); ?></span>
</div>
<div>
GET
</div>
<div>
GET
</div>
</div>
</div>
</div>
</div>
<!-- End -->
<?php } ?>
<!-- End -->
<?php } ?>
</div>
<div class="py-5 text-right">Show me more</div>
</div>
</div>
</body>

how to display 3 columns dynamic data from database using bootstrap 4

Following is my code I am displaying details as 3 columns per row using Bootstrap class row.
I tried like changing div and some condition
<div class="container">
<?php
if($lclResult->rowCount() > 0){
while($row = $lclResult->fetch(PDO::FETCH_ASSOC)) {
# code...
$lclUserName = $row['us_business_name'];
$lclImage1 = $row['us_image1'];
$lclCategory = $row['us_category'];
$lclArea = $row['us_area'];
?>
<div class="row">
<div class="col-sm-4">
<div class="card">
<img class="card-img-top " src="<?php echo $lclImage1 ?>" alt="Card image" style="width:100%; height: 158px;">
<div class="card-body">
<h4 class="card-title"><?php echo $lclUserName?></h4>
<p class="card-text" style="font-size: 25px;"><?php echo $lclCategory?></p>
<hr>
<i class="fa fa-map-marker" style="font-size: 23px;"><span> </span><?php echo $lclArea?></i>
<!-- See Profile -->
</div>
</div>
<?php
}
?>
</div>
<?php
} else {
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1> NO RESULT FOUND...</h1>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
I want to display 3 columns per row to display data. If anyone knows Please guide me with the above code.
Change your code like this
<div class="container">
<div class="row">
<?php
if($lclResult->rowCount() > 0){
while($row = $lclResult->fetch(PDO::FETCH_ASSOC)) {
# code...
$lclUserName = $row['us_business_name'];
$lclImage1 = $row['us_image1'];
$lclCategory = $row['us_category'];
$lclArea = $row['us_area'];
?>
<div class="col-sm-4">
<div class="card">
<img class="card-img-top " src="<?php echo $lclImage1 ?>" alt="Card image" style="width:100%; height: 158px;">
<div class="card-body">
<h4 class="card-title">
<?php echo $lclUserName?>
</h4>
<p class="card-text" style="font-size: 25px;">
<?php echo $lclCategory?>
</p>
<hr>
<i class="fa fa-map-marker" style="font-size: 23px;">
<span>
</span>
<?php echo $lclArea?>
</i>
<!-- See Profile -->
</div>
</div>
</div>
<?php
}
?>
<?php
} else {
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1> NO RESULT FOUND...
</h1>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>

Yii - foreach output exceeds 12 columns

I'm having a problem right now where my data exceeds 12 columns and it's looking distorted.
I tried to fiddle around with my foreach position and add clearfix but it doesn't work. How do I make sure that it will not exceed 12? Is it because there's 2 foreach in a row?
<div class="row">
<?php $count=0; foreach($model['organizations']['approve'] as $organization): ?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Manage</span>
<h3 class=""><?php echo $organization->title ?></h3>
</div>
<div class="ibox-content">
<?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
<span class="label label-primary pull-right">Visit</span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php $count++; endforeach; ?>
<div class="clearfix"></div>
<?php $count=0; foreach($model['organizations']['pending'] as $organization): ?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right badge badge-warning" ">Pending</span>
<!-- <?php echo Html::image(ImageHelper::thumb(50, 50, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive")); ?>
-->
<h3 class="no-margins"><?php echo $organization->title ?></h3>
<!-- <small><?php echo $organization->text_oneliner ?></small>
-->
</div>
<div class="ibox-content">
<?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
<span class="label label-primary pull-right">Visit</span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php $count++; endforeach; ?>
<div class="col-lg-4">
<div class="contact-box full-width light-green-bg">
<div class="col-xs-12">
<div class="center-block text-center margin-top-lg text-muted">
<i class="fa fa-plus-circle fa-2x"></i><br />Add
</div>
</div>
</div>
</div>
</div>
Any help would be greatly appreciated!
Hey try put this code before <div class="clearfix"></div>:
<?php
$count = 1;
foreach ($model['organizations']['approve'] as $organization) {
if ($count == 1 || $count % 3 == 1) {
?>
<div class="row">
<?php
}
?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Manage</span>
<h3 class=""><?php echo $organization->title ?></h3>
</div>
<div class="ibox-content">
<?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
<span class="label label-primary pull-right"><a
href="<?php echo $organization->url_website ?>"
class=" <?php echo empty($organization->url_website) ? 'disabled' : '' ?>"
target="_blank">Visit</a></span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php
if ($count % 3 == 0) {
?>
</div>
<?php }
$count++;
}
?>
<?php if ($count % 3 != 0) echo "</div>"; ?>
You can try our this. I just modified #Sador's answer. I hope it helps.
<div class="row">
<?php
$count = 1;
foreach ($model['organizations']['approve'] as $organization):
?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Manage</span>
<h3 class=""><?php echo $organization->title ?></h3>
</div>
<div class="ibox-content">
<?php /* echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive")); */ ?>
<span class="label label-primary pull-right">
Visit
</span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php if ($count % 3 == 0) { ?>
</div>
<div class="row">
<?php
}
$count++;
endforeach;
?>

How to display each 3 item in a rows and continues loop to end?

I have a list item Album contains 30 albums.
I tried to display all them in the browser with 1 rows contain 3 items.
With code like:
<div class="container">
<div class="row">
foreach($listAlbum as $item) {
<div class="col-md-4">$item['imgUrl']</div>
}
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
</div>
Note: I want for each continues to loop all .col-md-4.
If I again using foreach(listAlbum) through each .row. It will duplicate, I don't want this.
Have any idea to resolve my problem?
Edit: Full structure in .col-md-4:
<div class="news-post standard-post">
<div class="post-gallery">
<img src="upload/news-posts/st1.jpg" alt="">
</div>
<div class="post-content">
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</h2>
<ul class="post-tags">
<li><i class="fa fa-clock-o"></i>27-Nov-2016</li>
<li><i class="fa fa-comments-o"></i><span>23</span></li>
</ul>
</div>
</div>
You need a counter for the $listAlbum items. Increment the counter for each item and check if it is divisible by 3. If it is divisible by 3, re-open the row tag:
<?php
$listAlbum = [
['imgUrl' => 'url1'],
['imgUrl' => 'url2'],
['imgUrl' => 'url3'],
['imgUrl' => 'url4'],
['imgUrl' => 'url5'],
];
echo "<div class='container'>\n\t<div class='row'>\n";
$i = -1;
foreach ($listAlbum as $item) {
if (++$i && $i % 3 == 0)
echo "\t</div>\n\t<div class='row'>\n";
echo "\t\t<div class='col-md-4'>", $item['imgUrl'], "</div>\n";
}
if (++$i % 3)
echo str_repeat("\t\t<div class='col-md-4'></div>\n", 3 - $i % 3);
echo "\t</div>\n</div>";
Sample Output
<div class='container'>
<div class='row'>
<div class='col-md-4'>url1</div>
<div class='col-md-4'>url2</div>
<div class='col-md-4'>url3</div>
</div>
<div class='row'>
<div class='col-md-4'>url4</div>
<div class='col-md-4'>url5</div>
<div class='col-md-4'></div>
</div>
</div>
Try this:
<div class="container">
<div class="row">
<?php $col = 0; foreach($listAlbum as $item) {
if($col && !($col%3)){echo '</div><div class="row">';}
?>
<div class="col-md-4">$item['imgUrl']</div>
<?php $col++; } ?>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
Sample code:
<?php
for($i=1;$i<30;$i++){
$listAlbum[]= 'item '.$i;
}
?>
<div class="container">
<div class="row">
<?php $col = 0; foreach($listAlbum as $item) {
if($col && !($col%3)){echo '</div><div class="row">';}
?>
<div class="col-md-4"><?php echo $item ?></div>
<?php $col++; } ?>
</div>
Try this out, I am not sure of the content of $item['imgUrl']
<div class="container row">
<div class="col-md-12">
<?php foreach($listAlbum as $item) { ?>
<div class="col-md-4"> <?php $item['imgUrl'] ?></div>
<?php } ?>
</div>
</div>

php loop with complex html blocks

I have set of html block that are moved using jquery i need to make the correct loop of $posts array inside that i spent days trying to make it correct but it's not working for me.
The expected output should be
like this
Here is the my code
<?php if(!empty($posts)): ?>
<?php $count = 1; $countposts = count($posts); ?>
<?php for ($x = 0; $x <= $countposts; $x++): ?>
<?php if($x == 0): ?>
<div class="col-xs-12 col-sm-6 height-auto">
<?php else: ?>
<div class="col-sm-6 height-auto">
<?php endif; ?>
<?php foreach($posts as $post): ?>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
<?php endforeach; ?>
</div>
<?php endfor; ?>
<?php $count++; endif; ?>
This is HTML output that i need
<div class="col-xs-12 col-sm-6 height-auto">
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
</div>
<div class="col-sm-6 height-auto">
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
</div>
<div class="col-sm-6 height-auto">
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
</div>
<div class="col-sm-6 height-auto">
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
</div>
Notice here that the main blocks the first one looks like that
<div class="col-xs-12 col-sm-6 height-auto">
But the others are
<div class="col-sm-6 height-auto">
Also inside each main block there are only 2 posts
You can simply achieve this by starting the loop inside this <div class="col-sm-6 height-auto"> (the one that acts as a slide) then close and open it with a check for each 2 posts, for example it should look like this:
<div class="col-xs-12 col-sm-6 height-auto">
<?php $counter = 0; foreach($posts as $post) : $counter++; ?>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb"></div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">post title</h4>
<h6 class="text-right">author name</h6>
<p class="text-right">
description text
</p>
more
</div>
</div>
<?php if($counter == 2) : $counter = 0; ?>
</div><div class="col-sm-6 height-auto">
<?php endif; ?>
<?php endforeach; ?>
</div>
Hope I helped.
This is exactly what you want, im using a counter to determine the first post and so on:
<?php
$Posts = [
[
'title' => 'title',
'author' => 'author',
'desc' => 'desc',
'link' => 'link',
],
[
'title' => 'title',
'author' => 'author',
'desc' => 'desc',
'link' => 'link',
],
];
$Count = 0;
?>
<?php foreach( $Posts as $Post ) { ?>
<?php if ($Count == 0) {?>
<div class="col-xs-12 col-sm-6 height-auto">
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">
post title
</h4>
<h6 class="text-right">
author name
</h6>
<p class="text-right">
description text
</p>
<a href="#">
more
</a>
</div>
</div>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">
post title
</h4>
<h6 class="text-right">
author name
</h6>
<p class="text-right">
description text
</p>
<a href="#">
more
</a>
</div>
</div>
</div>
<?php } else { ?>
<div class="col-sm-6 height-auto">
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">
post title
</h4>
<h6 class="text-right">
author name
</h6>
<p class="text-right">
description text
</p>
<a href="#">
more
</a>
</div>
</div>
<div class="col-sm-12 boxed no-padding-left">
<div class="col-sm-3 no-padding-left artical-thumb">
</div>
<div class="col-sm-9 padding-bottom-10">
<h4 class="text-right text-primary">
post title
</h4>
<h6 class="text-right">
author name
</h6>
<p class="text-right">
description text
</p>
<a href="#">
more
</a>
</div>
</div>
</div>
<?php } ?>
<?php $Count++; ?>
<?php } ?>

Categories