Slick Slider - active when brand selected

20 views Asked by At

I'm trying to get a slick slider to pull through an uploaded image and link, from a custom taxonomy 'Brands'. When I create a new brand, I add an image for an advert, with a link to that advert.

The slick slider has two options - either it uses an uploaded image to the page, or if not, I need it to pull the ad that has been associate with the brand.

I have the slider working perfectly for the page images, but it isn't recognising the custom brand taxonomy when I have that ticked.

Can anyone help?

Code used below...

<div class="top-ad td-container-wrap">
<div class="td-container">
    <div class="td-crumb-container">
        <div class="slick-slider">
            <?php if( have_rows('top_advert_banner') ): ?>
                <?php
                // loop through the rows of data
                while ( have_rows('top_advert_banner') ) : the_row(); 
                    $image = get_sub_field('advert_image');
                    $size = 'full';
                    $link = get_sub_field('advert_link');
                ?>
                    <div class="ad-slide"> 
                        <?php if ($link) : ?><a href="<?php echo $link; ?>" target="_blank"><?php endif; ?>
                        <?php echo wp_get_attachment_image( $image, $size ); ?>     
                        <?php if ($link) : ?></a><?php endif; ?>                
                    </div>
                <?php endwhile; ?>
            <?php else : ?>        
                <?php
                $tax_term = wp_get_post_terms($post->ID, 'brands', array("fields" => "ids"));
                $term_id = ($tax_term[0]); 
                if( have_rows('top_advert_banner', 'brands_' . $term_id) ): ?>
                    <?php while( have_rows('top_advert_banner', 'brands_' . $term_id) ): the_row();
                        $image = get_sub_field('advert_image');
                        $size = 'full';
                        $link = get_sub_field('advert_link');
                    ?>
                        <div class="ad-slide"> 
                            <?php if ($link) : ?><a href="<?php echo $link; ?>" target="_blank"><?php endif; ?>
                            <?php echo wp_get_attachment_image( $image, $size ); ?>     
                            <?php if ($link) : ?></a><?php endif; ?>
                        </div>
                    <?php endwhile; ?>
                <?php else : ?>        
                    <?php if( have_rows('top_advert_banner', 28) ): ?>
                        <?php while ( have_rows('top_advert_banner', 28) ) : the_row(); 
                            $image = get_sub_field('advert_image');
                            $size = 'top-ad';
                            $link = get_sub_field('advert_link');
                        ?>
                            <div class="ad-slide"> 
                                <?php if ($link) : ?><a href="<?php echo $link; ?>" target="_blank"><?php endif; ?>
                                <?php echo wp_get_attachment_image( $image, $size ); ?>     
                                <?php if ($link) : ?></a><?php endif; ?>
                            </div>
                        <?php endwhile; ?>     
                    <?php endif; ?>    
                <?php endif; ?>
            <?php endif; ?> 
        </div>  
    </div>
</div>
0

There are 0 answers