<?php
/**
 * The template for displaying news section
 *
 * @package Oginer
 */

$blog_id = get_theme_mod( 'oginer_blog_id', 'blog' );
$blog_page  = get_theme_mod( 'oginer_blog_page' );

?>
<section id="<?php echo esc_attr( $blog_id ); ?>" class="blog-section mw-section">
	<div class="container">
		<?php if ( $blog_page ) { ?>
			<div class="row">
				<div class="section-title-box col-md-10 col-md-offset-1 text-center">
					<?php
						$args = array(
							'page_id' => absint( $blog_page ),
							'post_status' => 'publish'
						);

						$post_query = new WP_Query( $args );
						
						if( $post_query->have_posts() ): ?>
							<?php while ( $post_query->have_posts() ) : $post_query->the_post(); ?>
							
								<h2 class="section-title"><?php the_title(); ?></h2>
								
								<p><?php the_content(); ?></p>
								
								<?php  
							endwhile;
							
							wp_reset_postdata();
							
						endif; 
					?>
				</div>
			</div>
			<?php
		}
		?>
		<div class="row">
			<?php
				$blog_number = get_theme_mod( 'oginer_blog_number', 3 );
				$blog_args = array(
					'post_type' => 'post',
					'posts_per_page' => $blog_number,
					'ignore_sticky_posts' => true
				);
				
				$blog_query = new WP_Query( $blog_args );
				
				if( $blog_query->have_posts() ) {					
					while( $blog_query->have_posts() ) { 
					$blog_query->the_post();
					$image_id = get_post_thumbnail_id();
					$image_path = wp_get_attachment_image_src( $image_id, 'oginer-homepage-imgblog', true );
					$alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
						?>
						<article id="post-<?php the_ID(); ?>" <?php post_class( 'col-md-4' ); ?>>
							<div class="blog-item">
								<?php if( has_post_thumbnail() ) { ?>
									<div class="post-img">
										<figure>
											<a href="<?php the_permalink(); ?>">
												<img src="<?php echo esc_url( $image_path[0] ); ?>" alt="<?php echo esc_attr($alt); ?>" />
											</a>
										</figure>
										<div class="post-time">
											<span><?php echo the_time( 'd' ); ?></span>
											<span><?php echo the_time( 'M' ); ?></span>
										</div>
									</div>
								<?php } ?>
								<div class="post-content">
									<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
									<?php the_excerpt(); ?>
									<a href="<?php the_permalink(); ?>"><?php echo esc_html__('Read More','oginer') ?></a>
								</div>
							</div>
						</article>
						<?php
					}
				}
			wp_reset_postdata();
			?> 
		</div>
	</div>
</section>