<?php
/**
 * Custom Gallery Funtions
 *
 * @package Matrimony
 */
$matrimonial_gallery_option = get_theme_mod('matrimonial_gallery_option', 0 );
$matrimony_gallery_page  = get_theme_mod('matrimony_gallery_page',0); 
if( 0 ==  $matrimonial_gallery_option ){
	return;
}
?>
<section class="gallery-section default-padding">
    <div class="container">
    	<?php   if( !empty( $matrimony_gallery_page ) ): 
    		$args = array (                                 
	    		'page_id'           => absint( $matrimony_gallery_page ),
	    		'post_status'       => 'publish',
	    		'post_type'         => 'page',
    		);
    		$loop_gallery= new WP_Query($args);
    		if ( $loop_gallery->have_posts() ) : ?>
		        <div class="section-intro">
		        	<?php while ($loop_gallery->have_posts()) : $loop_gallery->the_post();?>
			            <header class="entry-header heading animated wow fadeInDown" data-wow-duration="1s">
			                <h4 class="entry-title"><?php the_title(); ?></h4>
			            </header>
			            <div class="header-img-wrap animated wow fadeInUp" data-wow-duration="1s">
			                 <?php the_post_thumbnail(); ?>
			            </div>
                        <?php 
                        $gallery_des_option = get_theme_mod('matrimonial_gallery_dec_option', 0 );
                        if( $gallery_des_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;  ?> 
        <?php 
	        $matrimony_gallery_cat = get_theme_mod('matrimonial_gallery_section_cat',0);
	        $number = get_theme_mod('matrimony_gallery_post_num',5);
	        $matrimony_cat_id = get_category_by_slug( $matrimony_gallery_cat );
	        $matrimony_url = get_category_link( $matrimony_cat_id );
	        $readmore = get_theme_mod( 'matrimony_gallery_text', '' );
	        $more_iteams = get_theme_mod( 'matrimony_gallery_more_iteams_text', '' );
	         ?>  
	        <div class="gallery-wrap">
	        	<?php
	        	if( !empty( $matrimony_gallery_cat) ) {
	        		$loop = new WP_Query(
	        		array(
	        			'post_type' => 'post',    
	        			'category_name' => esc_html($matrimony_gallery_cat),
	        			'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(); ?>
			        	<div class="gallery-item animated wow fadeInUp" data-wow-duration="1s">
							<?php the_post_thumbnail( 'matrimony-gallery-image' ); ?>
			                <?php if(!empty($readmore)){ ?>
				                <div class="gallery-contain">
				                    <a href="<?php the_permalink();?>"><?php echo esc_html( $readmore );?>
				                    </a>
				                </div>
			            	<?php } ?>
			            </div>
			        <?php endwhile;
				endif;
				wp_reset_postdata(); ?>    
	        </div>
	        <?php if($matrimony_gallery_cat){ ?>
	        	<a href="<?php echo esc_url( $matrimony_url );?>" class="button-full"> <?php echo esc_html( $more_iteams );?></a>
	    <?php } ?>
    </div>
</section> <!-- gallery-section end -->
