<?php
/**
 * Elementor Blog Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.5
 */
class Elementor_Blog_Widget extends \Elementor\Widget_Base {

	/**
	 * Get widget name.
	 *
	 * Retrieve Blog widget name.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'blog';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Blog widget title.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'Blog Post', 'endless-addons' );
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Blog widget icon.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fa fa-blog';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Blog widget belongs to.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'endless-elements' ];
	}

	/**
	 * Register Blog widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function register_controls() {

		$this->start_controls_section(
			'default_section',
			[    
				'label' => __( 'Settings', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'show_blog',
			[
				'label' => __( 'Show/Hide Blog Section', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => __( 'Show', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'hide' => [
						'title' => __( 'Hide', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'show',
				'toggle' => true
			]
		);

		$this->add_control(
			'select_blog_style',
			[
				'label' => __( 'Select Blog Style', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'style-01' => __( 'Style 01', 'endless-addons' ),
					'style-02' => __( 'Style 02', 'endless-addons' ),
					'style-03' => __( 'Style 03', 'endless-addons' ),
					'style-04' => __( 'Style 04', 'endless-addons' ),
					'style-05' => __( 'Style 05', 'endless-addons' ),
					'style-06' => __( 'Style 06', 'endless-addons' )
				],
				'default' => 'style-01'
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'blog_section',
			[
				'label' => __( 'Blog Section', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'section_title',
			[
				'label' => __( 'Section Title', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Title', 'endless-addons' ),
				'default'  => __( 'Design 01', 'endless-addons' )
			]
		);

		$this->add_control(
			'section_desc',
			[
				'label' => __( 'Section Description', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::WYSIWYG,
				'input_type' => 'WYSIWYG',
				'placeholder' => __( 'Description', 'endless-addons' ),
				'default' => __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt dolore magna aliqua. Quis ipsum suspendisse ultrices gravida.', 'endless-addons')
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'section_background',
				'label' => __( 'Background', 'plugin-domain' ),
				'types' => [ 'classic', 'gradient', 'video' ],
				'selector' => '{{WRAPPER}} .ea-blog-post-area',
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'blog_content',
			[
				'label' => __( 'Blog Content', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'blog_item_column',
			[
				'label' => __( 'Select Blog Column', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'columns-2' => __( '2', 'endless-addons' ),
					'columns-3' => __( '3', 'endless-addons' ),
					'columns-4' => __( '4', 'endless-addons' )
				],
				'default' => 'columns-3',
				'condition' => [
                    'select_blog_style' => array('style-01', 'style-03', 'style-04')
                ]
			]
		);

        $this->add_control(
			'blog_post_count',
			[
				'label' => __( 'Number of words', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::NUMBER,
				'input_type' => 'number',
				'default' => __( '20', 'endless-addons' ),
			]
		);

		$this->add_control(
			'show_blog_info',
			[
				'label' => __( 'Show Blog Info', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'yes' => [
						'title' => __( 'Yes', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'no' => [
						'title' => __( 'No', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'yes',
				'toggle' => true
			]
		);

        $this->add_control(
			'read_more_text',
			[
				'label' => __( 'Read More Text', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Text', 'endless-addons' ),
				'default' => __( 'Read More', 'endless-addons' ),
				'condition' => [
                    'select_blog_style' => array('style-01', 'style-03', 'style-05')
                ]
			]
		);

		$this->add_control(
			'blog_shape_img1',
			[
				'label' => __( 'Shape Image 1', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'show_label' => true,
				'condition' => [
                    'select_blog_style' => 'style-03'
                ]
			]
		);

		$this->add_control(
			'blog_shape_img2',
			[
				'label' => __( 'Shape Image 2', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'show_label' => true,
				'condition' => [
                    'select_blog_style' => 'style-03'
                ]
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'blog_sorting',
			[
				'label' => __( 'Blog Sorting', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);


		$this->add_control(
			'blog_category_select',
			[
				'label' => __( 'Sort By Multiple Categories', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'yes' => [
						'title' => __( 'Yes', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'no' => [
						'title' => __( 'No', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'no',
				'toggle' => true
			]
		);

		$this->add_control(
			'blog_category_multiple',
			[
				'label' => __( 'Write Category Name', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'cat1, cat2', 'endless-addons' ),
				'description' => esc_html__( 'Enter the category slugs separated by commas (Eg. cat1, cat2)', 'endless-addons' ),
				'condition' => [
                    'blog_category_select' => 'yes'
                ]
			]
		);

		$this->add_control(
			'blog_category_single',
			[
				'label' => __( 'Sort By Category', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'select',
				'options' => endless_addons_get_blog_cat_list(),
				'condition' => [
                    'blog_category_select' => 'no'
                ]
			]
		);

		$this->add_control(
			'blog_tag_select',
			[
				'label' => __( 'Sort By Multiple Tags', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'yes' => [
						'title' => __( 'Yes', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'no' => [
						'title' => __( 'No', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'no',
				'toggle' => true
			]
		);

		$this->add_control(
			'blog_tag_multiple',
			[
				'label' => __( 'Write Tag Name', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'tag1, tag2', 'endless-addons' ),
				'description' => esc_html__( 'Enter the tag slugs separated by commas (Eg. tag1, tag2)', 'endless-addons' ),
				'condition' => [
                    'blog_tag_select' => 'yes'
                ]
			]
		);

		$this->add_control(
			'blog_tag_single',
			[
				'label' => __( 'Sort By Tag', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'select',
				'options' => endless_addons_get_blog_tag_list(),
				'condition' => [
                    'blog_tag_select' => 'no'
                ]
			]
		);

        $this->add_control(
            'ea_blog_order',
            [
                'label' => esc_html__( 'Posts Order By', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'options' => [
                    'DESC'      => esc_html__( 'DESC', 'endless-addons' ),
                    'ASC'       => esc_html__( 'ASC', 'endless-addons' ),
                ],
                'default' => 'DESC',
            ]
        );

        $this->add_control(
            'ea_blog_count',
            [
                'label' => esc_html__( 'Number of Items', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'default' => 3,
                'condition' => [
                    'select_blog_style' => array('style-01', 'style-02', 'style-03', 'style-04', 'style-06')
                ]
            ]
        );

        $this->add_control(
            'ea_blog_offset',
            [
                'label' => esc_html__( 'Offset', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'description' => __('Skip number of posts', 'endless-addons'),
                'condition' => [
                    'select_blog_style' => array('style-01', 'style-02', 'style-03', 'style-04', 'style-06')
                ]
            ]
        );

		$this->end_controls_section();

		$this->start_controls_section(
			'section_style',
			[
				'label' => __( 'Section Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

		$this->add_control(
			'section_title_color',
			[
				'label' => __( 'Section Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-blog-post-area .section-title h2' => 'color: {{VALUE}}'
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'section_title_typography',
                'label' => __( 'Section Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-blog-post-area .section-title h2'
            ]
        );

        $this->add_control(
			'section_desc_color',
			[
				'label' => __( 'Section Description Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-blog-post-area .section-title p' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'section_desc_typography',
                'label' => __( 'Section Description Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-blog-post-area .section-title p'
            ]
        );

		$this->end_controls_section();

		$this->start_controls_section(
			'blog_style',
			[
				'label' => __( 'Blog Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

		$this->add_control(
			'blog_bg_color',
			[
				'label' => __( 'Blog Area Background Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-blog-post-area.ea-blog-post-bg-img::before' => 'background: {{VALUE}}'
                ],
                'condition' => [
                    'select_blog_style' => 'style-05'
                ]
			]
		);

		$this->add_control(
			'blog_img_height',
			[
				'label' => __( 'Blog Image Height', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-blog-post-area .ea-blog-img img' => 'height: {{SIZE}}{{UNIT}}',
				],
			]
		);

		$this->add_control(
			'blog_img_width',
			[
				'label' => __( 'Blog Image Width', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-blog-post-area .ea-blog-img img' => 'width: {{SIZE}}{{UNIT}}',
				],
			]
		);

        $this->add_control(
            'blog_img_border_radius',
            [
                'label' => __( 'Blog Image Border Radius', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'separator' => 'after',
                'selectors' => [
                    '{{WRAPPER}} .ea-blog-post-area .ea-blog-img img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

		$this->add_control(
			'blog_title_color',
			[
				'label' => __( 'Blog Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-blog-post-area .ea-blog-content h3 a' => 'color: {{VALUE}}'
                ]
			]
		);

		$this->add_control(
			'blog_title_hover_color',
			[
				'label' => __( 'Blog Title Hover Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-blog-post-area .ea-blog-content h3 a:hover' => 'color: {{VALUE}}'
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'blog_title_typography',
                'label' => __( 'Blog Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-blog-post-area .ea-blog-content h3'
            ]
        );

        $this->add_control(
			'blog_content_color',
			[
				'label' => __( 'Blog Content Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-blog-post-area .ea-blog-content p' => 'color: {{VALUE}}'
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'blog_content_typography',
                'label' => __( 'Blog Content Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-blog-post-area .ea-blog-content p'
            ]
        );

		$this->end_controls_section();

		$this->start_controls_section(
			'_section_overlay_style',
			[
				'label' => __('Background Overlay', 'endless-addons'),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => [
                    'select_blog_style' => array('style-01', 'style-02', 'style-03', 'style-04', 'style-06')
                ]
			]
		);

		$this->start_controls_tabs('_tabs_overlay_style');

		$this->start_controls_tab(
			'_tab_overlay_normal',
			[
				'label' => __('Normal', 'endless-addons'),
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_normal',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-blog-post-area',
			]
		);

		$this->end_controls_tab();

		$this->start_controls_tab(
			'_tab_overlay_hover',
			[
				'label' => __('Hover', 'endless-addons'),
			]
		);


		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_hover',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-blog-post-area:hover',
			]
		);

		$this->end_controls_tab();

		$this->end_controls_tabs();

		$this->end_controls_section();

	}

	/**
	 * Render Blog widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function render() {

		$settings = $this->get_settings_for_display(); ?>

		<!-- Blog Column Style -->
	    <?php if( $settings['blog_item_column'] == 'columns-2' ) :
			$blog_column = 'col-lg-6 col-md-6 col-sm-6';
		elseif( $settings['blog_item_column'] == 'columns-3' ) :
			$blog_column = 'col-lg-4 col-md-6 col-sm-6';
		elseif( $settings['blog_item_column'] == 'columns-4' ) :
			$blog_column = 'col-lg-3 col-md-6 col-sm-6';
		endif;

		if( $settings['blog_category_select'] == 'no' ) :
    		$endless_addons_cat_type = $settings['blog_category_single'];
        elseif( $settings['blog_category_select'] == 'yes' ) :
            $endless_addons_cat_type = $settings['blog_category_multiple'];
        endif;

        if( $settings['blog_tag_select'] == 'no' ) :
    		$endless_addons_tag_type = $settings['blog_tag_single'];
        elseif( $settings['blog_tag_select'] == 'yes' ) :
            $endless_addons_tag_type = $settings['blog_tag_multiple'];
        endif;

		// Post Query
        if( $settings['blog_category_single'] != '' ) {
            $args = array(
                'post_type'     => 'post',
                'posts_per_page'=> $settings['ea_blog_count'],
                'order'         => $settings['ea_blog_order'],
                'offset'        => $settings['ea_blog_offset'],
                'tag'           => $endless_addons_tag_type, 
                'tax_query'     => array(
                    array(
                        'taxonomy'      => 'category',
                        'field'         => 'slug',
                        'terms'         => $endless_addons_cat_type,
                        'hide_empty'    => false
                    )
                )
            );
            $args1 = array(
                'post_type'     => 'post',
                'posts_per_page'=> 2,
                'order'         => $settings['ea_blog_order'],
                'tag'           => $endless_addons_tag_type,
                'tax_query'     => array(
                    array(
                        'taxonomy'      => 'category',
                        'field'         => 'slug',
                        'terms'         => $endless_addons_cat_type,
                        'hide_empty'    => false
                    )
                )
            );
            $args2 = array(
                'post_type'     => 'post',
                'posts_per_page'=> 2,
                'offset' => 2,
                'order'         => $settings['ea_blog_order'],
                'tag'           => $endless_addons_tag_type,
                'tax_query'     => array(
                    array(
                        'taxonomy'      => 'category',
                        'field'         => 'slug',
                        'terms'         => $endless_addons_cat_type,
                        'hide_empty'    => false
                    )
                )
            );
        } 
        elseif( $settings['blog_category_multiple'] != '' ) {
            $args = array(
                'post_type'     => 'post',
                'posts_per_page'=> $settings['ea_blog_count'],
                'order'         => $settings['ea_blog_order'],
                'offset'        => $settings['ea_blog_offset'],
                'tag'           => $endless_addons_tag_type,
                'category_name' => $endless_addons_cat_type
            );
            $args1 = array(
                'post_type'     => 'post',
                'posts_per_page'=> 2,
                'order'         => $settings['ea_blog_order'],
                'tag'           => $endless_addons_tag_type,
                'category_name' => $endless_addons_cat_type
            );
            $args2 = array(
                'post_type'     => 'post',
                'posts_per_page'=> 2,
                'offset'        => 2,
                'order'         => $settings['ea_blog_order'],
                'tag'           => $endless_addons_tag_type,
                'category_name' => $endless_addons_cat_type
            );
        } 
        else {
            $args = array(
                'post_type'         => 'post',
                'posts_per_page'    => $settings['ea_blog_count'],
                'order'             => $settings['ea_blog_order'],
                'offset'            => $settings['ea_blog_offset'],
                'tag'               => $endless_addons_tag_type
            );
            $args1 = array(
                'post_type'         => 'post',
                'posts_per_page'    => 2,
                'order'             => $settings['ea_blog_order'],
                'tag'               => $endless_addons_tag_type 
            );
            $args2 = array(
                'post_type'         => 'post',
                'posts_per_page'    => 2,
                'offset'            => 2,
                'order'             => $settings['ea_blog_order'],
                'tag'               => $endless_addons_tag_type
            );
        }

        $post_array = new \WP_Query( $args );
        $post_array1 = new \WP_Query( $args1 );
        $post_array2 = new \WP_Query( $args2 );

		if( $settings['show_blog'] == 'show' ) :

			if( $settings['select_blog_style'] == 'style-01' ) : ?>
				<!-- Start EA Blog Post Design One Area -->
		        <section class="ea-blog-post-area ea-style-one pb-70">
		            <div class="container">
		                <div class="section-title">
		                    <h2><?php echo esc_html($settings['section_title']); ?></h2>
		                    <p><?php echo wp_kses_post($settings['section_desc']); ?></p>
		                </div>
		                <div class="row justify-content-center">
		                	<?php while( $post_array->have_posts() ) : $post_array->the_post(); ?>
			                    <div class="<?php echo esc_attr( $blog_column ); ?>">
			                        <div class="ea-single-blog-post">
			                            <div class="ea-blog-img">
			                                <a href="<?php the_permalink(); ?>">
			                                    <?php the_post_thumbnail(); ?>
			                                </a>
			                                <?php if($settings['show_blog_info'] == 'yes') : ?>
				                                <span class="ea-date">
				                                	<?php the_time('d M, Y'); ?>		
				                                </span>
			                                <?php endif; ?>
			                            </div>

			                            <div class="ea-blog-content">
			                            	<?php if($settings['show_blog_info'] == 'yes') : ?>
				                                <ul>
				                                	<?php if ( get_the_tags() ) {  ?>
				                                        <?php $post_tags = get_the_tags();
				                                        foreach ($post_tags as $post_tag ) {  
				                                            echo '<li><a href="'.esc_url(get_tag_link($post_tag->term_id)).'">'.esc_html($post_tag->name).'</a></li>';
				                                        } ?>
					                                <?php } ?>
				                                </ul>
			                                <?php endif; ?>
			                                <h3>
			                                    <a href="<?php the_permalink(); ?>">
			                                        <?php the_title(); ?>
			                                    </a>
			                                </h3>
			                                <p><?php ea_blog_read_more($settings['blog_post_count']); ?></p>
			                                <a href="<?php the_permalink(); ?>" class="read-more">
			                                    <?php echo esc_html($settings['read_more_text']); ?>
			                                    <i class='bx bx-right-arrow-alt'></i>
			                                </a>
			                            </div>
			                        </div>
			                    </div>
		                    <?php endwhile; ?>
                            <?php wp_reset_query(); ?>
		                </div>
		            </div>
		        </section>
		        <!-- End EA Blog Post Design One Area -->
		    <?php elseif( $settings['select_blog_style'] == 'style-02' ) : ?>
		    	<!-- Start EA Blog Post Design Two Area -->
		        <section class="ea-blog-post-area ea-style-two pb-70">
		            <div class="container">
		                <div class="section-title">
		                    <h2><?php echo esc_html($settings['section_title']); ?></h2>
		                    <p><?php echo wp_kses_post($settings['section_desc']); ?></p>
		                </div>
		                <div class="row">
		                	<?php while( $post_array->have_posts() ) : $post_array->the_post(); ?>
		                        <div class="ea-single-blog-post ea-style-two col-lg-6">
		                            <div class="ea-blog-img">
		                                <a href="<?php the_permalink(); ?>">
		                                    <?php the_post_thumbnail(); ?>
		                                </a>
		                            </div>
		                            <div class="ea-blog-content">
		                            	<?php if($settings['show_blog_info'] == 'yes') : ?>
			                                <ul>
			                                    <li><a href="<?php the_permalink(); ?>">
			                                        <i class='bx bx-calendar'></i>
			                                            <?php the_time('d M, Y'); ?>
			                                        </a>
			                                    </li>
			                                    <?php global $post;
			                                    $content = get_post_field( 'post_content', get_the_ID() );
			                                    $word_count = str_word_count( strip_tags( $content ) );
			                                    $readingtime = ceil($word_count / 200);
			                                    if ($readingtime == 1) {
			                                    $timer = " min read";
			                                    } else {
			                                    $timer = " mins read";
			                                    }
			                                    $totalreadingtime = $readingtime . $timer; ?>
			                                    <li><a href="<?php the_permalink(); ?>"><i class='bx bx-time'></i><?php echo esc_html__( $totalreadingtime); ?></a></li>
			                                </ul>
		                                <?php endif; ?>
		                                <h3>
		                                    <a href="<?php the_permalink(); ?>">
		                                        <?php the_title(); ?>
		                                    </a>
		                                </h3>
		                                <p><?php ea_blog_read_more($settings['blog_post_count']); ?></p>
		                            </div>
		                        </div>
		                    <?php endwhile; ?>
                            <?php wp_reset_query(); ?>
		                </div>
		            </div>
		        </section>
		        <!-- End EA Blog Post Design Two Area -->
		    <?php elseif( $settings['select_blog_style'] == 'style-03' ) : ?>
		    	<!-- Start EA Blog Post Design Three Area -->
		        <section class="ea-blog-post-area pb-70">
		            <div class="container">
		                <div class="section-title">
		                    <h2><?php echo esc_html($settings['section_title']); ?></h2>
		                    <p><?php echo wp_kses_post($settings['section_desc']); ?></p>
		                </div>
		                <div class="row justify-content-center">
		                	<?php while( $post_array->have_posts() ) : $post_array->the_post(); ?>
			                    <div class="<?php echo esc_attr( $blog_column ); ?>">
			                        <div class="ea-single-blog-post ea-style-three">
			                            <div class="ea-blog-img">
			                                <a href="<?php the_permalink(); ?>">
			                                    <?php the_post_thumbnail(); ?>
			                                </a>
			                            </div>
			                            <div class="ea-blog-content">
			                            	<?php if($settings['show_blog_info'] == 'yes') : ?>
				                                <ul>
				                                    <li>
				                                        <a href="<?php the_permalink(); ?>">
				                                        	<?php the_time('d / m / Y'); ?></a>
				                                    </li>
				                                    <li class="ea-right">
				                                        <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a>
				                                    </li>
				                                </ul>
			                                <?php endif; ?>
			                                <h3>
			                                    <a href="<?php the_permalink(); ?>">
			                                        <?php the_title(); ?>
			                                    </a>
			                                </h3>
			                                <p><?php ea_blog_read_more($settings['blog_post_count']); ?></p>
			                                <a href="<?php the_permalink(); ?>" class="read-more">
			                                    <?php echo esc_html($settings['read_more_text']); ?>
			                                </a>
			                            </div>
			                        </div>
			                    </div>
		                    <?php endwhile; ?>
                            <?php wp_reset_query(); ?>
		                </div>
		            </div>
		            <div class="ea-shape-1">
		                <?php if( ! $settings['blog_shape_img1']['url'] == '' ) : ?>
		                    <img src="<?php echo esc_url( $settings['blog_shape_img1']['url'] ); ?>" alt="image">
		                <?php endif; ?>
		            </div>
		            <div class="ea-shape-2">
		                <?php if( ! $settings['blog_shape_img2']['url'] == '' ) : ?>
		                    <img src="<?php echo esc_url( $settings['blog_shape_img2']['url'] ); ?>" alt="image">
		                <?php endif; ?>
		            </div>
		        </section>
		        <!-- End EA Blog Post Design Three Area -->
		    <?php elseif( $settings['select_blog_style'] == 'style-04' ) : ?>
		    	<!-- Start EA Blog Post Design Four Area -->
		        <section class="ea-blog-post-area pb-70">
		            <div class="container">
		                <div class="section-title">
		                    <h2><?php echo esc_html($settings['section_title']); ?></h2>
		                    <p><?php echo wp_kses_post($settings['section_desc']); ?></p>
		                </div>
		                <div class="row">
		                	<?php while( $post_array->have_posts() ) : $post_array->the_post(); ?>
			                    <div class="<?php echo esc_attr( $blog_column ); ?>">
			                        <div class="ea-single-blog-post ea-style-four">
			                            <div class="ea-blog-img">
			                                <a href="<?php the_permalink(); ?>">
			                                    <?php the_post_thumbnail(); ?>
			                                </a>
			                            </div>
			                            <div class="ea-blog-content">
			                            	<?php if($settings['show_blog_info'] == 'yes') : ?>
				                                <ul>
				                                    <li>
				                                        <a href="<?php the_permalink(); ?>">
				                                        	<i class='bx bx-calendar'></i>
				                                        	<?php the_time('d M, Y'); ?></a>
				                                    </li>
				                                    <?php global $post;
				                                    $content = get_post_field( 'post_content', get_the_ID() );
				                                    $word_count = str_word_count( strip_tags( $content ) );
				                                    $readingtime = ceil($word_count / 200);
				                                    if ($readingtime == 1) {
				                                    $timer = " min read";
				                                    } else {
				                                    $timer = " mins read";
				                                    }
				                                    $totalreadingtime = $readingtime . $timer; ?>
				                                    <li><a href="<?php the_permalink(); ?>"><i class='bx bx-time'></i><?php echo esc_html__( $totalreadingtime); ?></a></li>
				                                </ul>
			                                <?php endif; ?>
			                                <h3>
			                                    <a href="<?php the_permalink(); ?>">
			                                        <?php the_title(); ?>
			                                    </a>
			                                </h3>
			                                <p><?php ea_blog_read_more($settings['blog_post_count']); ?></p>
			                            </div>
			                        </div>
			                    </div>
		                    <?php endwhile; ?>
                            <?php wp_reset_query(); ?>
		                </div>
		            </div>
		        </section>
		        <!-- End EA Blog Post Design Four Area -->
		    <?php elseif( $settings['select_blog_style'] == 'style-05' ) : ?>
		    	<!-- Start EA Blog Post Design Five Area -->
		        <section class="ea-blog-post-area ea-style-five ea-blog-post-bg-img pt-100 pb-70">
		            <div class="container">
		                <div class="section-title white-title">
		                    <h2><?php echo esc_html($settings['section_title']); ?></h2>
		                    <p><?php echo wp_kses_post($settings['section_desc']); ?></p>
		                </div>
		                <div class="ea-blog-post-slider-wrap">
		                	<div class="owl-carousel owl-theme ea-blog-post-slider">
                                <div class="row">
				                	<?php while( $post_array1->have_posts() ) : $post_array1->the_post(); ?>
					                    <div class="col-lg-6">
					                        <div class="ea-single-blog-post ea-style-five">
					                            <div class="ea-blog-img">
					                                <a href="<?php the_permalink(); ?>">
					                                    <?php the_post_thumbnail(); ?>
					                                </a>
					                            </div>
					                            <div class="ea-blog-content">
					                            	<h3>
					                                    <a href="<?php the_permalink(); ?>">
					                                        <?php the_title(); ?>
					                                    </a>
					                                </h3>
					                                <?php if($settings['show_blog_info'] == 'yes') : ?>
						                                <ul>
						                                    <li>
						                                        <a href="<?php the_permalink(); ?>">
						                                        	<?php the_time('d M, Y'); ?></a>
						                                    </li>
						                                </ul>
					                                <?php endif; ?>
					                                <p><?php ea_blog_read_more($settings['blog_post_count']); ?></p>
					                                <a href="<?php the_permalink(); ?>" class="read-more">
					                                    <?php echo esc_html($settings['read_more_text']); ?>
					                                </a>
					                            </div>
					                        </div>
					                    </div>
				                    <?php endwhile; ?>
		                            <?php wp_reset_query(); ?>
		                        </div>
		                        <div class="row">
				                	<?php while( $post_array2->have_posts() ) : $post_array2->the_post(); ?>
					                    <div class="col-lg-6">
					                        <div class="ea-single-blog-post ea-style-five">
					                            <div class="ea-blog-img">
					                                <a href="<?php the_permalink(); ?>">
					                                    <?php the_post_thumbnail(); ?>
					                                </a>
					                            </div>
					                            <div class="ea-blog-content">
					                            	<h3>
					                                    <a href="<?php the_permalink(); ?>">
					                                        <?php the_title(); ?>
					                                    </a>
					                                </h3>
					                                <?php if($settings['show_blog_info'] == 'yes') : ?>
						                                <ul>
						                                    <li>
						                                        <a href="<?php the_permalink(); ?>">
						                                        	<?php the_time('d M, Y'); ?></a>
						                                    </li>
						                                </ul>
					                                <?php endif; ?>
					                                <p><?php ea_blog_read_more($settings['blog_post_count']); ?></p>
					                                <a href="<?php the_permalink(); ?>" class="read-more">
					                                    <?php echo esc_html($settings['read_more_text']); ?>
					                                </a>
					                            </div>
					                        </div>
					                    </div>
				                    <?php endwhile; ?>
		                            <?php wp_reset_query(); ?>
		                        </div>
	                        </div>
		                </div>
		            </div>
		        </section>
		        <!-- End EA Blog Post Design Five Area -->
		    <?php elseif( $settings['select_blog_style'] == 'style-06' ) : ?>
		    	<!-- Start EA Blog Post Design Six Area -->
		    	<div class="bg-shape">
			        <section class="ea-blog-post-area ea-style-six ptb-100">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html($settings['section_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['section_desc']); ?></p>
			                </div>
			                <div class="row">
			                	<?php while( $post_array->have_posts() ) : $post_array->the_post(); ?>
				                    <div class="ea-blogcol col-lg-6">
				                    	<?php global $post;
				                    	if (has_post_thumbnail( $post->ID ) ): ?>
										  <?php $ea_blog_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
									        <div class="ea-single-blog-post ea-style-six ea-single-bg" style="background-image: url('<?php echo esc_url( $ea_blog_image[0] ); ?>')">
										<?php else: ?>
											<div class="ea-single-blog-post ea-style-six">
										<?php endif; ?>
				                            <div class="ea-blog-content">
				                            	<?php if($settings['show_blog_info'] == 'yes') : ?>
					                                <ul>
					                                    <li>
					                                        <a href="<?php the_permalink(); ?>">
					                                        	<i class="bx bx-calendar"></i>
					                                        	<?php the_time('d M, Y'); ?></a>
					                                    </li>
					                                </ul>
				                                <?php endif; ?>
				                                <h3>
				                                    <a href="<?php the_permalink(); ?>">
				                                        <?php the_title(); ?>
				                                    </a>
				                                </h3>
				                                <?php ea_blog_read_more($settings['blog_post_count']); ?>
				                            </div>
				                        </div>
				                    </div>
			                    <?php endwhile; ?>
	                            <?php wp_reset_query(); ?>
			                </div>
			            </div>
			        </section>
			    </div>
		        <!-- End EA Blog Post Design Six Area -->
            <?php endif;

        endif;

    }

}
