<?php
/**
 * Custom Blog Funtions
 *
 * @package Matrimony
 */
$matrimony_blog_page  = get_theme_mod('matrimony_blog_page',0); 
$matrimonial_blog_option = get_theme_mod('matrimonial_blog_option', 0 );
if( 0 == $matrimonial_blog_option ){
	return;
} ?>
<section class="blog-section default-padding">
    <div class="container">
    	<?php   if( !empty( $matrimony_blog_page ) ): 
    		$args = array (                                 
    		'page_id'           => absint( $matrimony_blog_page ),
    		'post_status'       => 'publish',
    		'post_type'         => 'page',
    		);
    		$loop_blog= new WP_Query($args);
    		if ( $loop_blog->have_posts() ) : ?>
	 	        <div class="section-intro">
	 	        	<?php while ($loop_blog->have_posts()) : $loop_blog->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 
	                    $matrimonial_blog_dec_option = get_theme_mod('matrimonial_blog_dec_option', 0 );
	                    if( $matrimonial_blog_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; 
	                endwhile; ?>      
	 	        </div>
	 	    <?php endif;
	 	    wp_reset_postdata();
 	    endif;
 	     ?>
 	     <?php 
 	     $matrimonial_blog_section_cat = get_theme_mod('matrimonial_blog_section_cat',0);
 	     $matrimony_cat_id = get_category_by_slug( $matrimonial_blog_section_cat );
 	     $matrimony_url = get_category_link( $matrimony_cat_id );
 	     $number = get_theme_mod('matrimony_blog_post_num',5);
 	     $readmore = get_theme_mod( 'matrimony_blog_text','' );
 	     $matrimony_blog_more_iteams_text = get_theme_mod( 'matrimony_blog_more_iteams_text', '' );
 	      ?>    
	        <div class="blog-wrap">
	        	<?php
	        	if( !empty( $matrimonial_blog_section_cat) ) {
	        		$loop = new WP_Query(
	        		array(
	        			'post_type' => 'post',    
	        			'category_name' => esc_html($matrimonial_blog_section_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();  ?>
		 	            <article class="post animated wow fadeInUp" data-wow-duration="1s">
		 	                <figure>
		 	                    <?php the_post_thumbnail(); ?>
		 	                    <?php if(!empty($readmore)){ ?>
			 	                    <div class="fig-overlay">
			 	                       <a href="<?php the_permalink();?>"><?php echo esc_html( $readmore );?>
				                    </a>
			 	                    </div>
		 	                    <?php } ?>
		 	                </figure>
		 	                <div class="post-cat-list">
		 	                    <span class="cat-link">
		 	                       <?php matrimony_cat_links(); ?>
		 	                    </span>
		 	                </div>
		 	                <header class="entry-header">
		 	                    <h2 class="entry-title">
		 	                          <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
		 	                    </h2>
		 	                </header>
		 	                <div class="entry-content">
		 	                    <p>
		 	                        <?php echo esc_html(wp_trim_words(get_the_content(),30,'&hellip;')); ?>
		 	                    </p>
		 	                </div>
		 	            </article>
	  	            <?php endwhile;
	  	        endif; ?>      
	        </div>
	        <?php if($matrimonial_blog_section_cat){ ?>
	        <?php } ?>
    </div>
</section>
	 