Skip to content

Instantly share code, notes, and snippets.

@sarvar
Last active May 17, 2019 11:17
Show Gist options
  • Save sarvar/152420aa1534561c3a4272df81381537 to your computer and use it in GitHub Desktop.
Save sarvar/152420aa1534561c3a4272df81381537 to your computer and use it in GitHub Desktop.
ACF Repeater field and Bootstrap Carousel
@Jay17231
Copy link

This results in two slides one below each other instead of a carousel - Any fixes ?

@andy-rifle
Copy link

andy-rifle commented Sep 5, 2018

Hi Jay17231,

The solution is just to change <div class="item to <div class="carousel-item for BS4

@anish862
Copy link

anish862 commented Feb 1, 2019

Am trying to fetch from the custom post type "Carousel" with category_name, can you help on it??

<?php if( have_rows('carousel_slider') ): ?>
<div class="carousel_bg">
    <div class="container">
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <!-- Indicators -->
            <ol class="carousel-indicators">
                <?php query_posts( array( 'post_type' => 'Carousel', 'posts_per_page' => 1, 'orderby' => 'ID', 'order' => 'ASC','category_name'  => 'bon-vivant-premium-plywood') );
                $active = 'active';
                $num = 0;
                while ( have_rows('carousel_slider') ) : the_row();
                    ?>
                    <li data-target="#carousel-example-generic" data-slide-to="<?php echo $num ?>" class="<?php echo $active ?>"></li>
                    <?php
                    $active = '';
                    $num += 1;
                endwhile; ?>
            </ol>
            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <?php
				query_posts( array( 'post_type' => 'Carousel', 'posts_per_page' => 1, 'orderby' => 'ID', 'order' => 'ASC','category_name'  => 'bon-vivant-premium-plywood') );
                $active = 'active';
                while ( have_rows('carousel_slider') ) : the_row();
                    ?>
                    <div class="carousel-item <?php echo $active ?> screen08">
                        <div class="container">
                            <?php 
								$image = the_sub_field('image');
								if( !empty($image) ): ?>
									<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
								<?php endif; ?>
                        </div>
                    </div><!-- /item -->
                    <?php $active = '';
                endwhile;
                ?>
            </div>
        </div>
    </div>
</div><!-- /row -->

@anish862
Copy link

anish862 commented Feb 1, 2019

am trying to fetch from the custom post type Carousel with category name. nothing display can any one help me on these

<div class="carousel_bg">
    <div class="container">
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <!-- Indicators -->
            <ol class="carousel-indicators">
                <?php query_posts( array( 'post_type' => 'Carousel', 'posts_per_page' => 1, 'orderby' => 'ID', 'order' => 'ASC','category_name'  => 'bon-vivant-premium-plywood') );
                $active = 'active';
                $num = 0;
                while ( have_rows('carousel_slider') ) : the_row();
                    ?>
                    <li data-target="#carousel-example-generic" data-slide-to="<?php echo $num ?>" class="<?php echo $active ?>"></li>
                    <?php
                    $active = '';
                    $num += 1;
                endwhile; ?>
            </ol>
            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <?php
				query_posts( array( 'post_type' => 'Carousel', 'posts_per_page' => 1, 'orderby' => 'ID', 'order' => 'ASC','category_name'  => 'bon-vivant-premium-plywood') );
                $active = 'active';
                while ( have_rows('carousel_slider') ) : the_row();
                    ?>
                    <div class="carousel-item <?php echo $active ?> screen08">
                        <div class="container">
                            <?php 
								$image = the_sub_field('image');
								if( !empty($image) ): ?>
									<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
								<?php endif; ?>
                        </div>
                    </div><!-- /item -->
                    <?php $active = '';
                endwhile;
                ?>
            </div>
        </div>
    </div>
</div><!-- /row -->

@BradleyFletcher
Copy link

		    <?php if( have_rows('slides') ) { ?>
		    
		    <?php
			    $num = 0;
			    $active = 'active';
			?>
		    
			<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
				
				<ol class="carousel-indicators">
					
					<?php while( have_rows('slides') ) : the_row() ; ?>
						
					<li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $num; ?>" class="<?php echo $active; ?>"></li>
					
					<?php 
						$num++;
						$active = '';
					?>
					
					<?php endwhile; ?>
					
		  		</ol>
		  		
		  		<div class="carousel-inner">
		  			
		  			<?php $active = 'active'; ?>
		  			
		  			<?php while( have_rows('slides') ) : the_row() ;
			  			
			  			$image 		= get_sub_field('image');
			  			$mainText 	= get_sub_field('main_text');
			  			$subText 	= get_sub_field('sub_text');

		  			?>
		  			
		  			<div class="carousel-item <?php echo $active; ?>">
		  				<img class="d-block w-100" src="<?php echo $image['url'];  ?>" alt="<?php echo $image['alt'];  ?>">
		  				<div class="carousel-caption d-none d-md-block">
		  					<h5><?php echo $mainText; ?></h5>
		  					<p><?php echo $subText; ?></p>
		  				</div>
		    		</div>
		    		
		    		<?php $active = ''; ?>
		    		
		    		<?php endwhile; ?>

		  		
		  		</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>
			
			<?php  } ?>
				
	    </section>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment