<?php
/**
 * The template for displaying testimonial section
 *
 * @package Oginer
 */
 
$testimonial_id = get_theme_mod( 'oginer_testimonial_id', 'testimonial' );
$testimonial_bg = get_theme_mod( 'oginer_testimonial_bg' );
?>

<section id="<?php echo esc_attr( $testimonial_id ); ?>" class="mw-section testimonial bg" <?php if ( $testimonial_bg ) { ?> style="background-image: url( <?php echo esc_url( $testimonial_bg ); ?> );" <?php } ?>>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<div id="carousel-testimonial" class="carousel slide carousel-testimonial" data-ride="carousel">
					<?php
					$pages_testimonials = array();
					for ( $i = 0; $i <= 3; $i++ ) {
						$page = get_theme_mod( 'oginer_testimonial_page_' . $i );
						if ( '' != $page ) {
							$pages_testimonials[] = $page;
						}
					}
					if( count($pages_testimonials) > 0 ){
						if( count($pages_testimonials) > 1 ){
						?>
				
						<!-- Indicators -->
						<ol class="carousel-indicators">
							<?php
							for ( $i = 0; $i < count($pages_testimonials); $i++ ) {
								$active = ( $i == 0 ) ? 'active' : ''; 
								?>
								<li data-target="#carousel-testimonial" data-slide-to="<?php echo esc_attr( $i ); ?>" class="<?php echo esc_attr( $active ); ?>"></li>
								<?php
							}
							?>
						</ol>
						<?php } ?>
						
						<div class="carousel-inner">
							<?php
							$args = array(
								'post_type' => 'page',
								'post__in' => $pages_testimonials,
								'orderby' => 'post__in'
							);
							$query = new WP_Query( $args );
							if ( $query->have_posts() ) :
								$i = 0;
								while ( $query->have_posts() ) : $query->the_post();
								$active = ( $i == 0 ) ? 'active' : '';								
								?>
								<div class="item text-center <?php echo esc_attr( $active ); ?>">
									<?php 
										if ( has_post_thumbnail() ) { 
											the_post_thumbnail();
										}
									?>
									
									<div class="testimonial-caption">
										
										<h2><?php the_title(); ?></h2>
										
										<?php the_content(); ?>
										
									</div>
								</div>
								<?php $i++;
							endwhile;
							wp_reset_postdata();
						endif;
						?>
						</div>
					<?php } ?>
				</div>
			</div>
		</div>
	</div>
</section>