<?php

if ( ! function_exists( 'moment_home_about_section' ) ) :
    /**
     * About Section
     *
     * @since moment 1.0.0
     *
     * @param null
     * @return null
     *
     */
    function moment_home_about_section() {
        global $moment_customizer_all_values;
        if( 1 != $moment_customizer_all_values['moment-about-enable'] ){
            return null;
        }
        $moment_home_about_single_words = absint( $moment_customizer_all_values['moment-home-about-single-words'] );
        $moment_home_about_posts = absint($moment_customizer_all_values['moment-about-page']);
        $moment_home_about_button = esc_html($moment_customizer_all_values['moment-home-about-button-text'] );
        $moment_home_about_button_link = esc_url($moment_customizer_all_values['moment-home-about-button-link'] );

    ?>
    <?php
    if( !empty( $moment_home_about_posts )){
        $moment_feature_slider_args =    array(
            'post_type' => 'page',
            'p' => $moment_home_about_posts,
            'posts_per_page' => 1

        );
        $moment_fature_section_post_query = new WP_Query( $moment_feature_slider_args );
        if ( $moment_fature_section_post_query->have_posts() ) :
        while ( $moment_fature_section_post_query->have_posts() ) : $moment_fature_section_post_query->the_post();
        if(has_post_thumbnail()){
            $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
            $url = $thumb['0'];
        }
        else{
            $url = get_template_directory_uri() .'/assets/img/sayer.jpg';
        }
        ?>   

        <div class="light-wrapper">
            <div class="container inner">
                <div class="thin">
                    <div class="thumb-holder">
                        <img src="<?php echo esc_url($url)?>">
                    </div>
                    <h3 class="section-title text-center"><?php the_title(); ?></h3>
                    <p class="text-center">
                        <?php echo wp_kses_post(moment_words_count( $moment_home_about_single_words ,get_the_content()));; ?>
                    </p>
                    <div class="btn-holder"><a href="<?php 
                        if (empty($moment_home_about_button_link)) {
                            the_permalink();
                        }
                        else{
                            echo esc_url($moment_home_about_button_link);
                        }
                        ?>" class="about-button"> <?php echo esc_html($moment_home_about_button);?></a>
                    </div>                
                </div>
                <!-- /.thin -->
            <div class="divide10"></div>
            </div>
            <!-- /.container --> 
        </div>

        <?php
            endwhile;
        endif;
    }
    if( empty( $moment_home_about_posts )){ ?>
        <div class="light-wrapper">
            <div class="container inner">
                <div class="thin">
                <div class="thumb-holder">
                    <img src="<?php echo get_template_directory_uri() .'/assets/img/sayer.jpg';?>">
                </div>
                    <h3 class="section-title text-center"><?php echo __('About Photographer','moment'); ?></h3>
                    <p class="text-center"><?php echo __('Nullam quis risus eget urna mollis ornare vel eu leo. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec ullamcorper nulla non metus auctor fringilla. Donec sed odio dui.','moment'); ?></p>
                </div>
                <!-- /.thin -->
            <div class="divide10"></div>
            </div>
            <!-- /.container --> 
        </div>
    <?php 
    }
}
endif;
add_action( 'moment_homepage', 'moment_home_about_section', 20 );