0

I am trying to Create Carousel Slider in which Images get from the wp_get_attachment_image_url function and all other alt title and caption data it works correctly.

I am stuck at carousel Indicators I want to connect Indicators with upload means when I will add a photo in Upload Indicator automatically add, as well if I delete the upload photo, the indicator reduce their number.

Please Help in this Function.

//This Loop I am using in (Uploads to this Page or Post) wp_get_attachment_url Slider Images Work Correctly But how to Auto Add Indicators with Upload.

<div id="demo" class="carousel slide" data-ride="carousel"><div class="carousel-inner" role="listbox"> 

<?php
$images =& get_children( array (
    'post_parent' => $post->ID,
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'order' => 'ASC',
)); ?> <ul class="carousel-indicators"><!--how to set loop here--><li data-target="#demo" data-slide-to="0"></li><!--loop end--></ul>   <?php if ( empty($images) ) { /* no attachments here */ } else  { foreach ( $images as $attachment_id => $attachment ) { ?> /*Work Correctly*/ <div class="carousel-item" > <?php //you can use both methods Show Large small or medium images $result = wp_get_attachment_image_url($attachment_id, $size = 'medium', $icon); $results = wp_get_attachment_image_src($attachment_id, $size = 'large', $icon); /*Second Method very Simple and easy*/ $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true); $image_title = $attachment->post_title; $caption = $attachment->post_excerpt; $description = $image->post_content; <img src="<?php echo $results[0]; ?>" alt="<?php echo $alt; ?>" title="<?php echo $image_title; ?>" /> </div> <?php } //foreach ?> </div> <a class="carousel-control-prev" href="#demo" data-slide="prev"> <span class="carousel-control-prev-icon"></span </a> <a class="carousel-control-next" href="#demo" data-slide="next"> <span class="carousel-control-next-icon"></span> </a> </div> <?php } //else ?>
4
  • 2
    What slider are working with? Paste some code you have right now)
    – anton
    Apr 30, 2021 at 19:20
  • Hi, I added code please check I just need help in the <!--how to set loop here--> section?... Please Review Once...
    – stepiadm
    May 3, 2021 at 18:24
  • What slider do you use? Bootstrap carousel?
    – anton
    May 3, 2021 at 18:35
  • Yes! Bootstrap I want to add Indicators through PHP loop as you can see in Code, not Through javascript.
    – stepiadm
    May 3, 2021 at 18:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.