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

add_filter( 'excerpt_length', 'oginer_excerpt_featured', 999 );

$features_id = get_theme_mod( 'oginer_features_id', 'features' );
$features_page = get_theme_mod( 'oginer_features_page' );
?>

<section id="<?php echo esc_attr( $features_id ); ?>" class="mw-section features bg">
	<div class="container">
		<?php
			if ( $features_page ) {
				$args = array(
					'page_id' => absint( $features_page ),
					'post_status' => 'publish'
				);

				$post_query = new WP_Query( $args );
				
				if( $post_query->have_posts() ): ?>
					<div class="row">
						<div class="col-md-10 col-md-offset-1">
							<div class="section-title-box text-center">
									<?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(); ?>
							</div>
						</div>
					</div>
					<?php
				endif; 
			}
		?>
		<div class="row">
			<div class="col-md-4 text-center mw-animation" data-os-animation="fadeInUp">
				<?php if ( has_post_thumbnail( absint( $features_page ) ) ) : ?>

					<div class="featured-media">
			
						<?php echo get_the_post_thumbnail(absint( $features_page ),'full'); ?>
						
					</div><!-- .featured-media -->
					
				<?php endif; ?>
			</div>
			<div class="col-md-4 mw-animation" data-os-animation="fadeInDown">
				<?php
				$pages = array();
				for ( $i = 1; $i <= 3; $i++ ) {					
					$page = get_theme_mod( 'oginer_features_page_' . $i );
					if ( 'page-none-selected' != $page ) {
						$pages[] = $page;
					}
				}
				$args = array(
					'posts_per_page' => 3,
					'post_type' => 'page',
					'post__in' => $pages,
					'orderby' => 'post__in'
				);
				$query = new WP_Query( $args );
				if ( $query->have_posts() ) :
					$i = 1;
					while ( $query->have_posts() ) : $query->the_post();
					$icon = get_theme_mod( 'oginer_features_icon' . $i );
					if( $i == 1 ) { $mt70 = 'mt-70'; }else{ $mt70 = ''; };
					?>

					<div class="feature-box righr-feature-item <?php echo esc_attr( $mt70 ); ?>">
						<div class="left-feature-item-icon">
							<i class="fa <?php echo esc_attr( $icon ); ?>"></i>
						</div>
						
						<h3><?php the_title(); ?></h3>
						<?php the_excerpt(); ?>
					</div>
					<?php $i++;
					endwhile;
					wp_reset_postdata();
				endif;
				?>
			</div>
			<div class="col-md-4 mw-animation" data-os-animation="fadeInUp">
				<?php
				$pages2 = array();
				for ( $i = 4; $i <= 6; $i++ ) {					
					$page = get_theme_mod( 'oginer_features_page_' . $i );
					if ( 'page-none-selected' != $page ) {
						$pages2[] = $page;
					}
				}
				$args = array(
					'posts_per_page' => 3,
					'post_type' => 'page',
					'post__in' => $pages2,
					'orderby' => 'post__in'
				);
				$query = new WP_Query( $args );
				if ( $query->have_posts() ) :
					$i = 4;
					while ( $query->have_posts() ) : $query->the_post();
					$icon = get_theme_mod( 'oginer_features_icon' . $i );
					if( $i == 4 ) { $mt70 = 'mt-70'; }else{ $mt70 = ''; };
					?>

					<div class="feature-box righr-feature-item <?php echo esc_attr( $mt70 ); ?>">
						<div class="left-feature-item-icon">
							<i class="fa <?php echo esc_attr( $icon ); ?>"></i>
						</div>
						
						<h3><?php the_title(); ?></h3>
						<?php the_excerpt(); ?>
					</div>
					<?php $i++;
					endwhile;
					wp_reset_postdata();
				endif;
				?>
			</div>
		</div>
	</div>
</section>

<?php
remove_filter( 'excerpt_length', 'oginer_excerpt_featured', 999 );
?>