I'm trying to make a slider and it works perfectly when 3 images are uploaded in the backend. It doesn't work when there are fewer.
The slider is a standard Bootstrap slider as seen here
The "the_field('afbeelding')" is from Advanced custom fields WP plugin as seen here
In the WP backend a user can upload an image, the_field('afbeelding') will print the url to the image.
For example, if there are only 2 images then it should only show 2 slides.
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<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>
<!-- Wrapper for slides -->
<div class="carousel-inner" >
<div class="item active">
<img src="<?php the_field('afbeelding')?>" alt="<?php the_title() ?>">
</div>
<div class="item">
<img src="<?php the_field('afbeelding_2');?>" alt="">
</div>
<div class="item">
<img src="<?php the_field('afbeelding_3');?>" alt="">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
I tried to fix it by changing each item to this:
<?php if(isset(the_field('afbeelding_2'))){?>
<div class="item">
<img src="<?php the_field('afbeelding_2');?>" alt="">
</div>
<?php } ?>
But it didn't work...
Help would be very much appreciated!
you was almost there if you check the reference code for the advanced custom fields which you are using you will find out that if you want to check if the value exists for that field you need to use get_field() functions.
I didn't work before with this plugin but i believe the_field() is always returning true that's why you need to get_field() which return either true if the value exists or false if not and in this case your condition will work as expected .
<?php
if (get_field('afbeelding_2')) { ?>
<div class="item">
<img src="<?php the_field('afbeelding_2');?>" alt="">
</div>
<?php }?>
Reference
Related
So I've just been doing some homework and I've come across an issue and I can't seem to be able to fix it, I'm not sure if I'm missing something obvious or something but it's just not working.
First time using phpstorm btw
I'm using PHP files for a uni course I'm doing and I use the include function to attach this to the front page
I've gone through all these forums on bootstrap carousel errors and I tried even using a URL to see if that would work but it's not working still.
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="../c-images/picture1.jpeg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../c-images/picture2.jpeg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../c-images/picture3.jpeg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
this is the HTML code in a file named carousel.php
and then in the front page named index.php, I have an include that includes this carousel.php
include'Includes/carousel.php';
the includes are all in a separate folder named Includes
Images are in another separate folder but when I refer to them I do use the ../ to go back one and then use the correct names to get to the image and use it.
So I'm a bit confused what's wrong if there's any common errors or something I can do to fix this?
As Far as I can understand your code. you need to take care of few things. the carousel.php you are working as only contains HTML code. So keep it simple. Don't use
any php syntax in it and place the Code like this as shown Below :
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active">
</li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="../c-images/picture1.jpeg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../c-images/picture2.jpeg" alt="Second
slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../c-images/picture3.jpeg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button"
data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button"
data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
As I Have Removed quotes from around the Div.
and simply call the page using PHP as you are doing from index.php page. include'Includes/carousel.php';
But Remove Double quotes from there also and type it in under php Syntaxt as shown Below :
<?php include'Includes/carousel.php'; ?>
Ok i couldn't get it working.
But i figured if i added the html into the index.php instead of using include to include it into the page it might work, the images worked.
No to sure why by itself in an include file it didnt work but i will in the future look more into it.
Atleast i got the images working.
I have a custom post type that may or may not include images to display in a carousel/slideshow. How can I have the carousel display ONLY if there have been images added to the post via Advanced Custom Fields? Below is the code I have so far. It works other than if there aren't images associated with the post, the frontend still shows the carousel controls and whatnot.
To further this, it'd be great to know how to have the indicators auto populate with the number of images added. As of now I have the indicators commented out.
<!-- slideshow -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<!-- <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>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol> -->
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php if( have_rows('timeline_images') ): ?>
<?php while( have_rows('timeline_images') ): the_row();
// vars
$image = get_sub_field('timeline_image');
?>
<div class="item">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" title="<?php echo $image['title'] ?>" />
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!-- /slideshow -->
You can probably do the same with your indicators as you do with your images (not tested):
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php if( have_rows('timeline_images') ): ?>
<?php
$carrousselCount = 0;
while( have_rows('timeline_images') ): the_row();
$carrousselCount++;
?>
// indicators
<li data-target="#myCarousel" data-slide-to="<?php echo $carrousselCount ?>" class="<?php echo $carrousselCount === 0 ? 'active' : '' ?>"></li>
<?php endwhile; ?>
<?php endif; ?>
<!-- end ol -->
</ol>
</div>
Hi i have used bootstrap carousel in my website.I have used data animation effects for moving texts from right to left from up and down and for image animation effects.But the data animation effects is not working in codeigniter php.
<div id="carousel-example-generic" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
<li data-target="#carousel-example-generic" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<!-- First slide -->
<div class="item active ">
<h3 class="heading82">OPEN SOURCE <span class="heading81">C</span>ONTENT <span class="heading81">M</span>ANAGEMENT <span class="heading81">S</span>YSTEMS</h3>
<img src="<?php echo base_url();?>theme/slider/3_1 (4).png" class="heading84"><h3 class="heading83">complete control over the content of the website from personalized admin panel</h3><img src="<?php echo base_url();?>theme/slider/4_2 (4).png" class="heading85">
<div class="captions">
<img src="<?php echo base_url();?>theme/slider/z2.png" class="heading94" data-animation="animated bounceInRight">
<img src="<?php echo base_url();?>theme/slider/z1.png" class="heading95" data-animation="animated bounceInRight">
<img src="<?php echo base_url();?>theme/slider/z.png" class="heading95" data-animation="animated bounceInRight">
<img src="<?php echo base_url();?>theme/slider/z3 (3).png" class="heading96" data-animation="animated bounceInRight">
</div>
<div class="carousel-caption" >
<h3 data-animation="animated bounceInDown" class="heading86">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading87"> Easy edit, delete and create new content
</h3>
<h3 data-animation="animated bounceInDown" class="heading88">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading89"> Manage your own online store with little or zero technical expertise
</h3>
<h3 data-animation="animated bounceInDown" class="heading90">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading91"> Convert your traffic into customers
</h3>
<h3 data-animation="animated bounceInDown" class="heading92">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading93"> Custom Design templates to manage your blogs
</h3>
</div>
</div> <!-- /.item -->
<!-- Second slide -->
<div class="item ">
<h3 class="heading43">FULLY <span class="heading41">R</span>ESPONSIVE & <span class="heading41">SEO</span> OPTIMIZED <span class="heading41">W</span>EBSITE <span class="heading41">D</span>ESIGN</h3>
<img src="<?php echo base_url();?>theme/slider/1 (2).png" class="heading45"><h3 class="heading44">Optimal viewing experience with easy reading and navigation on different mobiles & tablets</h3><img src="<?php echo base_url();?>theme/slider/2 (2).png" class="heading42">
<div class="carousel-caption">
<h3 data-animation="animated bounceInLeft" class="heading46">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading47"> We design custom build high impact site that attracts your target audience
</h3>
<h3 data-animation="animated bounceInLeft" class="heading48">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading49"> Ultra Responsive Design using HTML & CSS3
</h3>
<h3 data-animation="animated bounceInLeft" class="heading50">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading51"> 100% compatibility in all mobile devices and browsers
</h3>
<h3 data-animation="animated bounceInLeft" class="heading52">
<img src="<?php echo base_url();?>theme/slider/5.png" class="heading53"> We build scalable and smarter business solutions
</h3>
</div>
</div><!-- /.item -->
</div><!-- /.carousel-inner -->
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div><!-- /.carousel -->
How to loop the data? All image are displaying at one slide other slides are empty.
<div class="container">
<br>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<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>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php foreach($banner as $data) { ?>
<div class="item active">
<img src="<?php echo base_url()?>uploads/banner/<?php echo $data['image']?>" alt="Chania" width="460" height="345">
</div>
<?php }?>
<div class="item">
<img src="<?php echo base_url()?>assets/image/c.jpg" alt="Chania" width="460" height="345">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
How to loop the data? All image are displaying at one slide other slides are empty.
Use the below code.
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php
$i = 0;
foreach($banner as $data) { ?>
<div class="item <?php echo $i==0 ? 'active' : ''; $i++; ?>">
<img src="<?php echo base_url()?>uploads/banner/<?php echo $data['image']?>" alt="Chania" width="460" height="345">
</div>
<?php }?>
</div>
I've used Bootstrap carousel in my webpage but there is a problem in the slides. The first image slides with content, second is blank, then third image slides, then third image there is blank page slide.
My code:
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" ></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2" class="active"></li>
</ol>
<div class="carousel-inner">
<div class="item">
<img src="/site/img/daa.jpg" >
</div>
<div class="item">
<img src="/site/img/2.jpg" >
</div>
<div class="item active">
<img src="/site/img/grad.jpg" >
</div>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>
</div>
No margins, no padding, no .left or .right , and finally no spaces in the code..
What could the problem be?
Your code has some issues im edited your code Look at new updated and now you can understand Bootstrap Carousel Plugin
The Carousel plugin is a component for cycling through elements, like a carousel (slideshow).
Learn more about it W3SCHOOL
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<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 class="carousel-inner" role="listbox">
<div class="item active">
<img class="first-slide" src="http://s32.postimg.org/osirordf9/2_black_wallpaper_pattern_preview.jpg" alt="First slide">
<div class="container">
</div>
</div>
<div class="item">
<img class="second-slide" src="http://s32.postimg.org/osirordf9/2_black_wallpaper_pattern_preview.jpg" alt="Second slide">
<div class="container">
</div>
</div>
<div class="item">
<img class="third-slide" src="http://s32.postimg.org/osirordf9/2_black_wallpaper_pattern_preview.jpg" alt="Third slide">
<div class="container">
</div>
</div>
</div>
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class
Thanks for your interest. I've used fiddle and tested my carousel, it worked fine there,
so after more effort, I detected the problem. It was because I have css file with
.next,.prev{
display: none !important;
}
but I don't understand deeply why it causes blank slide, not only white sides in my slides!
thanks again