So i made a blog with some posts, that contain a few images that i want to show in a carousel using Bootstrap. Right now, my code gets all the images and their URL's and i want to use those URL's in the image sources. The problem now is that the images do show, but half on top of eachother. I think the problem is in html in the foreach because they both have the "active" tag

Anybody has a better way to show these images in a carousel? Let me know

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
                    <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>
                      <div class="carousel-inner">
                            $attachments = get_attached_media('image', get_the_ID());
                            foreach ($attachments as $image) {
                                $full_img_url = wp_get_attachment_url($attachment->ID);
                                <div class="carousel-item active">
                                  <img class="d-block w-100" src="<?php echo wp_get_attachment_url($image->ID); ?>" alt="First slide">
                      <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 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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.