<?php
/**
 *
 * @package LZ Fitness Premium
 */

if(get_theme_mod('lz_fitness_blog_section_disable') != 'on' ){ 
	//wp_enqueue_script('slider', get_template_directory_uri().'/js/slider.js', array(), '1.1', true);
	?>
	<section id="blog-section" class="ht-section">
		<div class="lightbox">
			<div class="container">
				<div class=" wow fadeInUp" data-wow-duration="1s">
					<?php
					$lz_fitness_blog_page_id = get_theme_mod('lz_fitness_blog_page');
					$lz_fitness_blog_sub_title = get_theme_mod('lz_fitness_blog_sub_title', 'There are many variations passes Lorem Ipsum available but the majority have suffered alteation some form.');
					$lz_fitness_blog_title = get_theme_mod('lz_fitness_blog_title', 'RECENT BLOG');
					// echo 'count'. 
					$countword=str_word_count($lz_fitness_blog_title);
 					// echo ' hLF '.
					$halfWd = floor($countword / 2);
					$wds = explode(' ', $lz_fitness_blog_title);
					$lz_fitness_blog_title_new = '';
					foreach($wds as $k=>$wd){
						if($k == $halfWd){
							$lz_fitness_blog_title_new .= '<span>';
						}
						$lz_fitness_blog_title_new .= $wd.' ';
						if(($k+1) == $countword){
							$lz_fitness_blog_title_new .= '</span>';
						}
					}	
					?>
					<?php if($lz_fitness_blog_title || $lz_fitness_blog_title_new){ ?>
						<div class="row">
							<div class="ht-section-title-tagline">
								<?php if($lz_fitness_blog_title){ ?>
									<h2 class="ht-section-title lz-blog-heading"><?php echo ($lz_fitness_blog_title); ?></h2>
								<?php } ?>
								<div class="clearfix"></div>
								<?php if($lz_fitness_blog_sub_title){ ?>
									<div class="col-md-6 col-md-offset-3 lz-blog-text"><?php echo esc_html($lz_fitness_blog_sub_title); ?></div>
								<?php } ?>
								<div class="clearfix"></div> 
							</div>
						</div>
					<?php } ?>
					<div class="clearfix"></div>
					
					<?php
					$showStatic = true;
					for( $i = 3; $i < 4; $i++ ){
						$lz_fitness_blog_page_id = get_theme_mod('lz_fitness_blog_page'.$i); 
						if(!empty($lz_fitness_blog_page_id)){
							$showStatic = false;
							break;
						}
					}

					?>
					
					<div class="ht-blog-wrap">
						<div class="ht-blog-post">						
							<!-- <button class="slide-prev ctrl-btn pro-prev fa fa-chevron-left"></button>
							<button class="ctrl-btn pro-next fa fa-chevron-right slide-next"></button> -->
							
								<?php 
								$lz_fitness_blog_post_count = get_theme_mod('lz_fitness_blog_post_count', 2 );
								$lz_fitness_blog_cat_exclude = get_theme_mod('lz_fitness_blog_cat_exclude');
								$lz_fitness_blog_cat_exclude = explode(',', $lz_fitness_blog_cat_exclude);
								$args = array(
									'posts_per_page' => absint($lz_fitness_blog_post_count),
									'category__not_in' => $lz_fitness_blog_cat_exclude
								);

								$item = 0;

								$query = new WP_Query($args);
								if($query -> have_posts()):
									while($query -> have_posts()) : $query -> the_post();
										$item++;
										$lz_fitness_image = wp_get_attachment_image_src(get_post_thumbnail_id() , 'total-blog-thumb');
										if(has_post_thumbnail()){
											$img = esc_url($lz_fitness_image[0]);
										}
										if(empty($lz_fitness_image)){
											$img = get_template_directory_uri().'/images/blog.jpg';
										}
										?>
										<div class="col-md-6 col-sm-6 padding0">
											<div class="box-panels">
												<div class="ht-blog-thumbnail padding0 col-md-6 col-sm-6">												
													<a href="<?php the_permalink(); ?>">
														<img class="blog-img" src="<?php echo $img; ?>" alt="<?php the_title(); ?>">
													</a>
												</div>
												<div class="ht-blog-excerpt col-md-6 col-sm-6 textcenter">
													<!--<div class="ht-blog-date text-center">
														<i class="fa fa-calendar-o" aria-hidden="true"></i>
														<?php //echo get_the_date( 'j' ); ?>
														<?php //echo get_the_date( 'M' ); ?>
														<?php //echo get_the_date( 'Y' ); ?>
													</div>-->
													<div class="box-text">
														<h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
														<div class="clearfix"></div>
														 <div class="ht-blog-date text-center">
															<i class="fa fa-calendar" aria-hidden="true"></i><?php echo get_the_date( 'd M Y' ); ?>
														</div>
														<p>
															<?php 
															if(has_excerpt()){
																echo get_the_excerpt();
															}else{
																echo lz_fitness_excerpt( get_the_content() , 110);
															}
															?>
														</p>
														<div class="clearfix"></div>	
									<?php
										$blosecbtntxt = get_theme_mod('blosecbtntxt', 'Read More'); 
									?>			
														<div class="blog-read-more">
															<a href="<?php the_permalink(); ?>"><?php echo ($blosecbtntxt);  ?></a>
														</div>
															
														</div>
													</div>					
													<div class="clearfix"></div>
												</div>	
											</div>						
											<?php
										endwhile;
									endif;
									wp_reset_postdata();
									?>
							</div>
							<div class="clearfix"></div>
						</div>
					</div>
				</div>
				<div class="clearfix"></div>
			</div>

		</section>

	<?php }