<?php
/**
 * Buzz_Agency Feature Section Functions And Definations
 *
 * @package Buzz_Agency
 */
add_action( 'buzz_agency_slider_callback_action',function(){
        $slider_option 		= get_theme_mod('buzz_agency_homepage_setting_slider_option',0);
        $slider_category 	= get_theme_mod( 'buzz_agency_slider_section_cat' );
        $number 			= get_theme_mod('buzz_agency_slider_num',5);
        $slider_readmore 	= esc_html(get_theme_mod( 'buzz_agency_slider_readmore',esc_html__('Learn More','buzz-agency') ) );    
        if($slider_option == '1'){
            ?>
            <div class="banner-rounded-bg">
                <span class="banner-shade-1">
                    <span class="banner-shade-2">
                    </span>
                </span>
            </div>
            <section class="featured-slider ">
    
                <div class="owl-carousel owl-theme main-slider">
                    <?php
                    if( !empty( $slider_category) ) {
                        $loop = new WP_Query(
                            array(
                                'post_type' => 'post',    
                                'category_name' => esc_html($slider_category),
                                'posts_per_page' => absint( $number ),  
                            )
                        );
                    }else{
                        $loop = new WP_Query( array( 'post_type'=>'post','posts_per_page'=>absint( $number ), ) );
                    }   
                    if($loop->have_posts() ) {

                        while($loop->have_posts() ) {
                            $loop->the_post();
                            $image = wp_get_attachment_url( get_post_thumbnail_id());
                            ?>
                            <div class="slider-content">

                                <div class="slider-text">
                                    <h2 class="slider-title"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                    <?php if(!empty($slider_readmore)){
                                        ?>
                                        <a href="<?php the_permalink();?>" class="box-button"><?php echo esc_html($slider_readmore);?><span></span></a>
                                        <?php
                                    }
                                    ?>
                                </div>
                                <figure class="slider-image">
                                    <img src="<?php echo esc_url($image);?>" />
                                </figure>

                            </div>
                            <?php 
                        }
                        wp_reset_postdata();
                    }
                    ?> 
                </div>

            </section> <!-- featured-slider ends here -->
            <?php
        }
    }, 10 );	
