I am trying to display videos as a slideshow inside bootstrap modal dynamically. But when videos are loaded, the corresponding play button functions as carousel left indicator. And also the video is auto-playing. I also tried using tag, which stops the auto-play, but still the play button functioning as carousel left indicator. Thanks in advance.
Below is my code.
<div class="modal fade and carousel slide" id="video">
<div class="modal-dialog" style="margin-top:250px;" >
<div class="modal-content">
<div class="modal-body">
<div class="carousel-inner">
<?php
$id=$_GET['id'];
//$i=0;
$qryr="select * from released_movies where rel_id='$id' ";
$qryrr=$con->query($qryr);
while($rrr=$qryrr->fetch_assoc()){
$film=$rrr['rel_movies'];
$qq="select * from events where film='$film'";
$qrr=$con->query($qq);
while($roo=$qrr->fetch_assoc()){
$rowss[] = $roo;
}
?>
<ol class="carousel-indicators">
<?php
$i = 1; //Counter
foreach ($rowss as $roo): //Foreach
$ol_class = ($i == 1) ? 'active' : ''; //Set class active for only indicator which belongs to respective Image
?>
<!--Here I add the counter to data-slide attribute and add class to indicator-->
<li data-target="#video" data-slide-to="<?php echo $i;?>" class="<?php echo $ol_class; ?>"></li>
<?php $i++; ?>
<?php endforeach; ?> <!--Close Foreach-->
</ol>
<?php
$i = 1; //Counter
foreach ($rowss as $roo): //Foreach
$item_class = ($i == 1) ? 'item active' : 'item'; //Set class active for image which is showing
?>
<div class="<?php echo $item_class; ?>"> <!-- Define Active Class Here-->
<iframe width="100%" height="500px" src="../AbaamAdmin/Events_Videos/<?php echo $roo['event_videos'];?>" frameborder="0" allowfullscreen></iframe>
</div>
<?php $i++; ?>
<?php endforeach; ?> <!-- Close Foreach-->
</div> <!-- /.item active-->
<a class="left carousel-control" href="#video" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<!-- <span class="glyphicons glyphicons-left-arrow"></span>-->
</a>
<a class="right carousel-control" href="#video" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<!--<span class="glyphicons glyphicons-right-arrow"></span>-->
</a>
<?php } ?>
</div> <!-- /.carousel-inner -->
</div><!-- /.modal-body -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
In your approach, some div elements, selectors are misplaced and one key div is missing, need some CSS changes required.
"carousel slide" in Modal HTML (Remove it)
<div class="carousel-inner"> is misplaced, it should come after <ol class="carousel-indicators"></ol>
Missing key carousel Element <div id="selector" class="carousel slide" data-ride="carousel"> Add it after modal-body
In Prev and Next button you are targeting href="#video" which is the id of Modal
In carousel indicators you are targeting data-target="#video" which is the id of Modal
CSS Changes required to fix the issue when clicking on Play / Stop button causing the video slide to next, Reason the Next / Previous button is overlapping the video control, following changes in CSS will fix the issue
.carousel-control {
bottom: 55px !important;
}
To stop the auto play, add autoplay=false in video iframe.
Final HTML will be
Note: I named the carousel selector id videobox
<div class="modal fade and" id="video">
<div class="modal-dialog" style="margin-top:250px;" >
<div class="modal-content">
<div class="modal-body">
<div id="videobox" class="carousel slide" data-ride="carousel">
<?php
$id=$_GET['id'];
//$i=0;
$qryr="select * from released_movies where rel_id='$id' ";
$qryrr=$con->query($qryr);
while($rrr=$qryrr->fetch_assoc()){
$film=$rrr['rel_movies'];
$qq="select * from events where film='$film'";
$qrr=$con->query($qq);
while($roo=$qrr->fetch_assoc()){
$rowss[] = $roo;
}
}
?>
<ol class="carousel-indicators">
<?php
$i = 1; //Counter
foreach ($rowss as $roo):
$ol_class = ($i == 1) ? 'active' : '';
?>
<li data-target="#videobox" data-slide-to="<?php echo $i;?>" class="<?php echo $ol_class; ?>"></li>
<?php $i++; ?>
<?php endforeach; ?>
</ol>
<div class="carousel-inner">
<?php
$i = 1; //Counter
foreach ($rowss as $roo):
$item_class = ($i == 1) ? 'item active' : 'item';
?>
<div class="<?php echo $item_class; ?>">
<iframe width="100%" height="500px" src="../AbaamAdmin/Events_Videos/<?php echo $roo['event_videos'];?>" frameborder="0" allowfullscreen autoplay="false"></iframe>
</div>
<?php $i++; ?>
<?php endforeach; ?>
</div> <!-- /.item active-->
<a class="left carousel-control" href="#videobox" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<!-- <span class="glyphicons glyphicons-left-arrow"></span>-->
</a>
<a class="right carousel-control" href="#videobox" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<!--<span class="glyphicons glyphicons-right-arrow"></span>-->
</a>
</div> <!-- /.carousel-inner -->
</div><!-- /.modal-body -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Fiddle
Related
Hello i am trying to display 3 post item of bootstrap carousel in Microweber. I am trying my luck here as not much info can be found in microweber as i am stuck for a few days. Here is my code.
<?php if (!empty($data)): ?>
<script>mw.require("<?php print $config['url_to_module']; ?>css/style.css", true); </script>
<?php $rand = 'item_carousel_'.$params['id']; $id = 'carousel_'.$params['id']; ?>
<div id="<?php print $id; ?>" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php $count = -1; foreach($data as $item): ?>
<?php $count++; ?>
<div class="carousel-item <?php if($count == 0){ print 'active ';} ?>">
<div class="col-12 col-md-4">
<div class="card mb-2">
<?php if($item['tn_image']): ?>
<?php endif; ?>
<div class="card-body">
<h4 class="text-center card-title"><?php print $item['title'] ?></h4>
<p class="card-text"><?php print $item['description']; ?></p>
</div>
</div>
</div>
</div>
<?php endforeach ; ?>
</div>
<!--Controls-->
<a class="carousel-control-prev " href="#<?php print $id; ?>" role="button" data-slide="prev">
<span class="fas fa-chevron-circle-left fa-2x" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#<?php print $id; ?>" role="button" data-slide="next">
<span class="fas fa-chevron-circle-right fa-2x" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!--/.Controls-->
</div>
<?php else : ?>
<?php endif; ?>
Currently it is display like this
But i want it to display 3 image in a row and using the control to rotate the next 3 post item.
1 - which template you are using?
2 - you can use slidesToShow: 3 in slick slider init
For example:
$('.multiple-items').slick({
infinite: true,
slidesToShow: 3,
slidesToScroll: 3
});
I have added the bootstrap carousel in which the div item is created in the for loop shown below. I have 9 small image in each item div which is dynamically getting populated. Now on carousel play i see the div item changes with change of active class but what i see is first div item content is also visible when the second item div is active similarly when 3rd item div gets active 1st and 2nd div items are visible too. Also the data-pause="hover" is not working.
<div class="col-md-4 col-md-offset-4">
<div id="custCarousel" class="carousel slide" data-ride="carousel" data-pause="hover">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#custCarousel" data-slide-to="0" class="active"></li>
<li data-target="#custCarousel" data-slide-to="1"></li>
<li data-target="#custCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php
$counttoken = 9;
$loop = round($arrloop/9);
$k=0;
for($j=0;$j<$loop;$j++)
{
if($k==0){$act='active';}else{$act ='';}
echo '<div class="item '.$act.'">';
for($i=0; $i<$counttoken;$i++)
{
$img = $data[$rand_keys[$i]];
echo "<img src=".$img[2]." alt=".$img[0]." width='100' />";
}
$counttoken = $counttoken + 9;
$k++;
echo '</div>';
}
?>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#custCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#custCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
Sorry, it was my bad i made an error in my php code to update the for loop. Here below is the updated code and it's working perfect now.
<?php
$counttoken = 9;
$loop = round($arrloop/9);
$k=0;
$l=0
for($j=0;$j<$loop;$j++)
{
if($k==0){$act='active';}else{$act ='';}
echo '<div class="item '.$act.'">';
for($i=$l; $i<$counttoken;$i++)
{
$img = $data[$rand_keys[$i]];
echo "<img src=".$img[2]." alt=".$img[0]." width='100' />";
}
$l = $l+9;
$counttoken = $counttoken + 9;
$k++;
echo '</div>';
}
?>
I am trying to do the Cart slider which can be seen at http://bootsnipp.com/snippets/Pbnxx
I am struggling with proper PHP syntax. Can anyone help me out?
The way I see it that I need to prepend .item and .row for every 4 columns, but something is glitching and doesn't work as expected
<div class="container">
<div class="row">
<div class="col-md-9">
<h3>TITLE </h3>
</div>
<div class="col-md-3">
<!-- Controls -->
<div class="controls pull-right hidden-xs">
<a class="left fa fa-chevron-left btn btn-success" href="#carousel-example"
data-slide="prev"></a>
<a class="right fa fa-chevron-right btn btn-success" href="#carousel-example"
data-slide="next"></a>
</div>
</div>
</div>
<div id="carousel-example" class="carousel slide hidden-xs" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php
while ( $query->have_posts() ) :
$query->the_post();
// make new slide every 4 columns
if($i % 4 == 0) : ?>
<div class="item <?php if($a++ == 0) echo 'active'; ?>">
<div class="row">
<?php endif; ?>
<div class="col-sm-3">
<div class="col-item">
<?php echo $i; ?>
</div>
</div>
<!-- end slide every 4 columns -->
<?php if($i++ % 4 == 0) : ?>
</div> <!-- row -->
</div> <!-- slide -->
<?php endif; ?>
<?php endwhile; ?>
</div> <!-- end carousel -->
</div> <!-- carousel-example -->
</div> <!-- container -->
I think your .row should be also .item because you want to slide 4 items at time.
Here you have my code using smarty. I used array_chunk($items, 4) and nested loops.
<div class="carousel-inner">
{foreach $recipebox.recipes as $key=>$recipeSet}
{if $key == 0}
<div class="row item active">
{else}
<div class="row item">
{/if}
{foreach $recipeSet as $recipe }
<div class="col-xs-3">
// box content
</div>
{/foreach}
</div>
{/foreach}
</div>
<img src="../AbaamAdmin/Released_Movies/<?php echo $row['rel_movies_pics'];?>" style="width:330px;height:300px;" >
When I click the above link I need to get the data-id value, and I need to fetch images from database using this value and need to create a image slideshow. The bootstrap modal poopup code is also in the same page. The below is my popup code.
<div class="modal fade and carousel slide" id="lightbox">
<div class="modal-dialog" style="margin-top:250px;vertical-align:middle;" >
<div class="modal-content">
<div class="modal-body">
<div class="carousel-inner">
<?php
$id=$_SESSION['relid'];
//$i=0;
$qry="select rel_movies from released_movies where rel_id='$id' ";
$qryr=$con->query($qry);
while($rr=$qryr->fetch_assoc())
{
$film=$rr['rel_movies'];
$q="select * from gallery where category='$film'";
$qr=$con->query($q);
while($r=$qr->fetch_assoc())
{
$rows[] = $r;
}
?>
<ol class="carousel-indicators">
<?php
$i = 1; //Counter
foreach ($rows as $r): //Foreach
$ol_class = ($i == 1) ? 'active' : ''; //Set class active for only indicator which belongs to respective Image
?>
<!--Here I add the counter to data-slide attribute and add class to indicator-->
<li data-target="#lightbox" data-slide-to="<?php echo $i;?>" class="<?php echo $ol_class; ?>"></li>
<?php $i++; ?>
<?php endforeach; ?> <!--Close Foreach-->
</ol>
<?php
$i = 1; //Counter
foreach ($rows as $r): //Foreach
$item_class = ($i == 1) ? 'item active' : 'item'; //Set class active for image which is showing
?>
<div class="<?php echo $item_class; ?>"> <!-- Define Active Class Here-->
<img src="../AbaamAdmin/uploads/<?php echo $r['images'];?>" width="900px" height="500px" >
</div>
<?php $i++; ?>
<?php endforeach; ?> <!-- Close Foreach-->
</div> <!-- /.item active-->
<a class="left carousel-control" href="#lightbox" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#lightbox" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
<?php }?>
</div> <!-- /.carousel-inner -->
</div><!-- /.modal-body -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
In place of $id=$_SESSION['relid']; I need to get the value from data-id. How this is possible. Thanks in advance.
geeks please help,
I have a problem with the usage of array keys with the while loop.
I'm trying to display the twitter bootstrap slider images by looping from the database with this code:
<div id="slider">
<!--Code for make home images slide show-->
<div id="myCarousel" class="carousel slide">
<!-- here comes the engine to run the sliders -->
<?php
$query = 'SELECT * FROM banners WHERE status = 1 ORDER BY id ASC';
?>
<div class="carousel-inner">
<?php
if ($r = mysql_query($query , $conn)) { //run the query
$row = mysql_fetch_array($r);
reset($row);
while (list($key, $value) = each($row)) {
if ($key == 0) { ?>
<div class="item active">
<img src="images/homeimages/<?php echo $value['image'];?>" alt="<?php echo $value['title'];?>">
<!-- <img src="images/homeimages/one.jpg" alt=""> -->
<div class="carousel-caption">
<!-- <h4>First Thumbnail label</h4> -->
<p><i><?php echo $value['title'];?></i></p>
</div>
</div>
<?php }else{ ?>
<div class="item">
<img src="images/homeimages/<?php echo $value['image'];?>" alt="<?php echo $value['title'];?>">
<!-- <img src="images/homeimages/one.jpg" alt=""> -->
<div class="carousel-caption">
<!-- <h4>First Thumbnail label</h4> -->
<p><i><?php echo $value['title'];?></i></p>
</div>
</div>
<?php }
}
}else {
print '<p style="color: red;">Could not retrieve the slider:<br />' . mysql_error($dbc) . '.</p>';
} ?>
</div>
<!-- <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a> -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
</div>
</div><!-- endof slider -->`
.
as`it's well known the first slider image of twitter bootstrap must have the class of active to make sure it loads faster. I need to pick the first slider image from an array and add the class of active into it while the rest of the slider images remains the same without an active class.
can someone please tell me where i'm messing up with my codes?
Try this:
<div class="carousel-inner">
<?php
if ($r = mysql_query($query , $conn)) {
$count = 0;
while ($row = mysql_fetch_array($r){
if ($count == 0){?>
<div class="item active">
<?php}
else { ?>
<div class="item">
<?php}?>
<img src="images/homeimages/<?php echo $row['image'];?>" alt="<?php echo $row['title'];?>">
<div class="carousel-caption">
<p><i><?php echo $row['title'];?></i></p>
</div>
</div>
<?php
}
$count ++;
}
}
else {
print '<p style="color: red;">Could not retrieve the slider:<br />' . mysql_error($dbc) . '.</p>';
}