<?php
/**
 * Custom Gift Funtions
 *
 * @package Matrimony
 */
$matrimony_gift_page_one  = get_theme_mod('matrimony_gift_page_one',0); 
$matrimonial_gift_section_cat = get_theme_mod('matrimonial_gift_section_cat',0);
$number_one = get_theme_mod('matrimony_gift_post_num',5);
$matrimony_gift_image = get_theme_mod('matrimony_gift_image','');
$matrimonial_gift_option = get_theme_mod('matrimonial_gift_option', 0 );
if(	0 == $matrimonial_gift_option ){
	return;
}
?>	
<section class="gift-section default-padding">
	    <div class="container">
	    	<?php   if( !empty( $matrimony_gift_page_one ) ): 
	    		$args = array (                                 
	    		'page_id'           => absint( $matrimony_gift_page_one ),
	    		'post_status'       => 'publish',
	    		'post_type'         => 'page',
	    		);
	    		$loop_gift= new WP_Query($args);
	    		if ( $loop_gift->have_posts() ) : ?>
			        <div class="section-intro">
			        	<?php while ($loop_gift->have_posts()) : $loop_gift->the_post();?>
				            <header class="entry-header heading">
				                <h4 class="entry-title"> <?php the_title(); ?> </h4>
				            </header>
				            <div class="header-img-wrap">
				               <?php the_post_thumbnail(); ?>
				            </div>
	                        <?php 
	                        $matrimonial_gift_dec_option = get_theme_mod('matrimonial_gift_dec_option', 0 );
	                        if( $matrimonial_gift_dec_option == 1 ):
                        	?>
								<div class="section-description animated wow fadeInUp" data-wow-duration="1s">
									<p> <?php echo esc_html(wp_trim_words(get_the_content(),30,'&hellip;')); ?></p>
								</div>
		                    <?php endif; ?>
	            		<?php endwhile; ?>  
			        </div>
			    <?php endif;
			    wp_reset_postdata();
			    endif;
		    ?>    
	        <div class="gift-wrap">
	        	<?php
	        	if( !empty( $matrimonial_gift_section_cat) ) {
	        		$loop = new WP_Query(
	        		array(
	        			'post_type' => 'post',    
	        			'category_name' => esc_html($matrimonial_gift_section_cat),
	        			'posts_per_page' => absint( $number_one ),  
	        			)
	        		);
	        	}	else{
	        		$loop = new WP_Query( 
	        			array( 
	        				'post_type'=>'post',
	        				'posts_per_page'=>absint( $number_one ), 
	        			) 
        			);
	        	}   
	        	?>
		            <div class="gift-wrap-left animated wow fadeInLeft" data-wow-duration="1s">
		            	<?php
		            	if($loop->have_posts() ):
		            	    	while($loop->have_posts() ): $loop->the_post(); ?>
				                <div class="gift-item">
				                    <figure>
				                         <?php the_post_thumbnail(); ?>
				                    </figure>
				                    <h4 class="entry-title"><a href="<?php the_permalink();?>"> <?php the_title(); ?></a> </h4>
				                </div>
			            	<?php endwhile;
			        	endif;
			        	wp_reset_postdata(); ?>         
		            </div>
            	<?php
            	$matrimony_gift_page  = get_theme_mod('matrimony_gift_page',0);
            	$matrimony_gift_second_image = get_theme_mod('matrimony_gift_second_image','');
            	?>
            	<?php   if( !empty( $matrimony_gift_page ) ): 
            		$args = array (                                 
            		'page_id'           => absint( $matrimony_gift_page ),
            		'post_status'       => 'publish',
            		'post_type'         => 'page',
            		);
            		$loop_gift = new WP_Query($args);
            		if ( $loop_gift->have_posts() ) : ?>
						<?php while ($loop_gift->have_posts()) : $loop_gift->the_post();?>
				            <div class="gift-appreciation animated wow fadeInUp" data-wow-duration="1s">
				                <header class="entry-header">
			        	            <?php if( !empty( $matrimony_gift_second_image) ) { ?>
			        		            <span class="header-icon">
			        		                <img src="<?php echo esc_url($matrimony_gift_second_image);?>" />
			        		            </span>
			        	            <?php } ?>
				                    <h4 class="entry-title"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h4>
				                </header>
				                <div class="entry-content">
				                   <p><?php echo esc_html(wp_trim_words(get_the_content(),32,'&hellip;')); ?></p>
				                </div>
				                <div class="header-img-wrap">
				                    <?php the_post_thumbnail(); ?>
				                </div>	
				            </div>
						<?php endwhile; ?> 
	        	    <?php endif;
	        	    wp_reset_postdata();
                endif; ?>     
	            <?php
	            	$gift_cat_two = get_theme_mod('matrimonial_gift_section_second_cat',0);
	            	$number_two = get_theme_mod('matrimony_gift_second_post_num',5);
	            ?>
            	<?php
            	if( !empty( $gift_cat_two) ) {
            		$loop = new WP_Query(
            		array(
            			'post_type' => 'post',    
            			'category_name' => esc_html($gift_cat_two),
            			'posts_per_page' => absint( $number_two ),  
            			)
            		);
            	}else{
            		$loop = new WP_Query( 
            			array( 
            				'post_type'=>'post',
            				'posts_per_page'=>absint( $number_two ), 
            			) 
            		);
            	}   
            	?>
	            <div class="gift-wrap-right animated wow fadeInRight" data-wow-duration="1s">
            		<?php if($loop->have_posts() ):
            	    	while($loop->have_posts() ) : $loop->the_post(); ?>
						<div class="gift-item">
							<figure>
								<?php the_post_thumbnail(); ?>
							</figure>
							<h4 class="entry-title"><a href="<?php the_permalink();?>"> <?php the_title(); ?></h4>
						</div>
		                <?php endwhile;
		            endif;
	            	wp_reset_postdata(); ?>     
	            </div>
	        </div>
	    </div>
</section><!--gift-section end -->
