Support

Account

Home Forums ACF PRO Put styles to file with unique ID Reply To: Put styles to file with unique ID

  • Maybe I could use an easier method. Like this (extra while loop with $i++) to get unique classes:

    <?php if( have_rows('_post_slider') ) : ?>
    
        <?php $flexibleSlider = 0 ?>
        <?php while( have_rows('_post_slider') ) : the_row(); ?>
            <?php $flexibleSlider++; ?>
        <?php endwhile; ?>
    
        <div class="row slider-wrapper">
            <div class="col-md-12">
            <div class="slider_inner slider-<?php echo $flexibleSlider; ?> ">
                <?php 
                    $count_dataindex = 0;
                    $count_dataid = 0;
                ?>
                <?php while( have_rows('_post_slider') ) : the_row(); ?>
                    <?php $count_dataindex++; ?>
                    <article class="" data-index="<?php echo $count_dataindex; ?>" data-slidertitle="<?php the_sub_field('_headline'); ?>">
                        <?php $image = get_sub_field('_bild'); ?>
                        <figure style="background-image: url(<?php echo $image['sizes']['img-l']; ?>)"></figure>
                        <?php if ( get_sub_field('_headline') ) : ?>
                            <div class="slider-headline" data-id="<?php echo $count_dataid; ?>">
                                <?php echo get_sub_field('_headline'); ?>
                            </div>
                        <?php endif; ?>
                    </article>
                <?php endwhile; ?>
            </div>
            </div>
        </div>
    
        <script>
            jQuery(document).ready(function($){
                $('.slider-<?php echo $flexibleSlider; ?> ').slick({
                    infinite: true,
                    slidesToShow: 1,
                    slidesToScroll: 1
                });
            });
        </script>
        
    <?php endif; ?>

    EDIT: Hm no. I get “slider-4”, “slider-3”, “slider-3” … .