<?php

// Prevent Direct Access
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$blog_suptitle = get_theme_mod('blog_suptitle');
$blog_title = get_theme_mod('blog_title');
$blog_section_date = get_theme_mod('blog_section_date', true);
$blog_section_author = get_theme_mod('blog_section_author', true);
$blog_count = get_theme_mod('blog_count', '3');
$blog_section_all_posts_button = get_theme_mod('blog_section_all_posts_button', true);
$blog_section_all_posts_button_text = get_theme_mod('blog_section_all_posts_button_text', esc_html__('View All Posts', 'maxo-fa'));
$section_id = get_theme_mod('blog_menu_id', 'blog');
?>

<section id="<?php echo $section_id ?>" class="padding bglight darkcolor">
	<div class="container">
		<div class="row">
			<div class="col-sm-12 text-center">
			
				<div class="title_block heading_space">
					<?php
					if( $blog_suptitle != '' ){ echo '<p class="title bottom0">'.$blog_suptitle.'</p>'; }
					if( $blog_title != '' ){ echo '<h2>'.$blog_title.'</h2>'; }
					?>
				</div>
				
				<div class="our-blog">
					<div class="swiper-container">
					
						<div class="swiper-wrapper">
						
							<?php
							$blog_posts = new WP_Query(array(
								'posts_per_page' => $blog_count
							));

							if( $blog_posts -> have_posts() ){
								while( $blog_posts -> have_posts() ){
									$blog_posts -> the_post();
							?>

							<div class="swiper-slide">
								<div class="ourblog">
									<div class="row">
									
										<div class="col-sm-12">
											<div class="image">

												<?php if( has_post_thumbnail() ){ ?>
												<a href="<?php the_permalink() ?>"><?php the_post_thumbnail() ?></a>
												<?php } ?>
												
												<?php if( $blog_section_date || $blog_section_author ){ ?>
												<div class="desc_tags">
												
													<?php if($blog_section_date){ ?>
													<span class="ivydatedate"><?php the_time('j F Y') ?></span>
													<?php } ?>

													<?php if($blog_section_author){ ?>
													<a href="<?php echo get_author_posts_url( get_the_author_meta('ID') ) ?>" class="ivydatedate"><?php echo esc_html__('By', 'maxo-fa').': '.get_the_author() ?></a>
													<?php } ?>
													
												</div>
												<?php } ?>
												
											</div>
										</div>
										
										<div class="col-sm-12">
											<div class="blog_desc">
												<h3 class="top25 bottom20"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h3>
												<p class="bottom20"><?php echo wp_trim_words(get_the_excerpt(), (has_post_thumbnail() ? 29 : 40), ' ...') ?></p>
											</div>
										</div>
										
									</div>
								</div>
							</div>
							
							<?php
								}
							}

							wp_reset_postdata();
							?>
						
						</div>
						
						<div class="swiper-pagination top20"></div>
						
					</div>
				</div>
				
				<?php if( $blog_section_all_posts_button ){ ?>
				<div class="text-center all_posts_button">
					<a href="<?php echo get_permalink( get_option('page_for_posts') ) ?>" class="button dark"><?php echo $blog_section_all_posts_button_text ?></a>
				</div>
				<?php } ?>

			</div>
		</div>
	</div>
</section>