<?php
	$leatherhouse_blog_disabled       = get_theme_mod( 'leatherhouse_blog_disabled', true );

	// Theme check
	$activate_theme_data = wp_get_theme(); // getting current theme data.
	$activate_theme      = $activate_theme_data->name;
	if ( 'Leather House' == $activate_theme ) {	
		$leatherhouse_blog_area_title     = get_theme_mod( 'leatherhouse_blog_area_title', 'News From Our Wearhouse' );
		$leatherhouse_blog_area_des       = get_theme_mod( 'leatherhouse_blog_area_des', 'Stay updated with the latest news by reading our articles written by content writers in the industry.' );
		$leatherhouse_blog_button_text     = get_theme_mod( 'leatherhouse_blog_button_text', 'More Blogs' );
	} elseif ( 'Modern House' == $activate_theme ) { 
		$leatherhouse_blog_area_title     = get_theme_mod( 'leatherhouse_blog_area_title', 'Modern Living, Trending Now' );
		$leatherhouse_blog_area_des       = get_theme_mod( 'leatherhouse_blog_area_des', 'Catch the latest trends, innovations, and expert takes on design, architecture, and luxury living.' );
		$leatherhouse_blog_button_text     = get_theme_mod( 'leatherhouse_blog_button_text', 'See whats new' );
	}
	$leatherhouse_blog_container_size = get_theme_mod( 'leatherhouse_blog_container_size', 'container-full' );
	$leatherhouse_theme_blog_category = get_theme_mod( 'leatherhouse_theme_blog_category' );
if ( true === $leatherhouse_blog_disabled ) {
	?>	
<section id="post-section" class="post-section av-py-default blog-home shapes-section">
	<div class="<?php echo esc_attr( $leatherhouse_blog_container_size ); ?>">
		<?php if ( ! empty( $leatherhouse_blog_area_title ) || ! empty( $leatherhouse_blog_area_des ) ) : ?>
			<div class="av-columns-area">
				<div class="av-column-12">
					<div class="heading-default text-center wow">
						<?php if ( ! empty( $leatherhouse_blog_area_title ) ) : ?>
							<h3><?php echo wp_kses_post( $leatherhouse_blog_area_title ); ?></h3>
						<?php endif; ?>
						<?php if ( ! empty( $leatherhouse_blog_area_des ) ) : ?>
							<p><?php echo wp_kses_post( $leatherhouse_blog_area_des ); ?></p>
						<?php endif; ?>	
					</div>
				</div>
			</div>
		<?php endif; ?>
		<div class="av-columns-area">
			<div class="av-column-12">
				<div class="post-carousel owl-carousel owl-theme">
					<?php
					$leatherhouse_blog_args = array(
						'post_type'      => 'post',
						'posts_per_page' => 3,
						//'category__in'   => $leatherhouse_theme_blog_category,
						'post__not_in'   => get_option( 'sticky_posts' ),
					);

					$leatherhouse_wp_query = new WP_Query( $leatherhouse_blog_args );
					if ( $leatherhouse_wp_query ) {
						$post_count = 0;
						while ( $leatherhouse_wp_query->have_posts() ) :
							$leatherhouse_wp_query->the_post();

							?>
								<article class="post-items">
								<?php if ( has_post_thumbnail() ) { ?>
										<figure class="post-image">
											<div class="featured-image">
												<a href="<?php echo esc_url( get_permalink() ); ?>" class="post-hover">
													<?php the_post_thumbnail(); ?>
												</a>
											</div>
										</figure>
										<span class="post-date"> <a href="<?php echo esc_url( get_month_link( get_post_time( 'Y' ), get_post_time( 'm' ) ) ); ?>"><span><?php echo esc_html( get_the_date( 'j' ) ); ?></span><?php echo esc_html( get_the_date( 'M, Y' ) ); ?></a> </span>
									<?php } ?>
									<div class="post-content">
								
									<?php
									if ( is_single() ) :

										the_title( '<h5 class="post-title">', '</h5>' );

										else :

											the_title( sprintf( '<h5 class="post-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h5>' );

											endif;
										?>

										<div class="post-footer">
											<a href="<?php the_permalink(); ?>" class="blog-button"><?php esc_html_e('Continue Reading', 'leather-house'); ?> <i class="fa fa-long-arrow-right"></i></a>
											<!--<span class="post-count">
											<?php
											if ( $post_count < 9 ) :
												$post_count = $post_count + 1;
												echo sprintf( esc_html( '0 %s', 'leather-house' ), $post_count );
												else :
													echo esc_html( $post_count + 1 );
													endif;
												?>
											</span>-->
										</div>
									</div>
								</article>
								<?php
								endwhile;
					}
						wp_reset_postdata();
					?>
				</div>

			</div>
		</div>
		<?php
		$leatherhouse_blog_button_disabled = get_theme_mod( 'leatherhouse_blog_button_disabled', true );
		$leatherhouse_blog_button_link     = get_theme_mod( 'leatherhouse_blog_button_link', '#' );
		if ( true === $leatherhouse_blog_button_disabled ) {
			if ( ! empty( $leatherhouse_blog_button_text ) ) :
				?>
				<div class="blog-button" style="text-align:center; margin-top:15px;">
					<a href="<?php echo esc_url( $leatherhouse_blog_button_link ); ?>" target='_blank' 
						class="av-btn-primary"><?php echo esc_html( $leatherhouse_blog_button_text ); ?> 
					</a>
				</div>
			<?php endif; ?>
		<?php } ?>
	</div>
</section>

	<?php
		$leatherhouse_blog_column_layout    = get_theme_mod( 'leatherhouse_blog_column_layout', '3' );
	?>
<script>
	jQuery( document ).ready(function() {
		jQuery(".post-carousel").owlCarousel({
			rtl: jQuery("html").attr("dir") == 'rtl' ? true : false,
			items: <?php echo $leatherhouse_blog_column_layout; ?>,
			navText: ['<i class="fa fa-arrow-left"></i>', '<i class="fa fa-arrow-right"></i>'],
			margin: 30,
			stagePadding: 15,
			autoplay: false,
			touchDrag: false,
			mouseDrag: false,
			responsive:{
				0:{
					items:1
				},
				600:{
					items:3
				},
				1000:{
					items:3
				}
			}
		});
	});
</script>
	<?php } 
