<?php
/**
 * Template part for displaying home testimonials section.
 *
 * @package University_Hub
 */

?>
<?php
	$testimonials_title    = university_hub_get_option( 'testimonials_title' );
	$testimonials_number   = university_hub_get_option( 'testimonials_number' );
	$testimonials_category = university_hub_get_option( 'testimonials_category' );
?>
<div id="university-hub-testimonials" class="home-section-testimonials">
	<div class="container">
		<h2 class="section-title"><?php echo esc_html( $testimonials_title ); ?></h2>
		<?php
		$qargs = array(
			'posts_per_page' => absint( $testimonials_number ),
			'no_found_rows'  => true,
			);

		if ( absint( $testimonials_category ) > 0  ) {
			$qargs['cat'] = absint( $testimonials_category );
		}

		// Fetch posts.
		$the_query = new WP_Query( $qargs );
		?>
		<?php if ( $the_query->have_posts() ) : ?>
			<div class="testimonials-wrapper">
				<div class="cycle-slideshow"
					data-cycle-slides="> article"
					data-cycle-auto-height="container"
					data-cycle-timeout="4000"
					>
				<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
					<article class="testimonials-item">
						<div class="testimonials-item-inner">
							<?php if ( has_post_thumbnail() ) : ?>
								<a class="testimonials-thumb" href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
							<?php endif; ?>
							<div class="testimonials-content-area">
								<?php the_excerpt(); ?>
							</div><!-- .testimonials-content-area -->
							<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
						</div><!-- .testimonials-item-inner -->
					</article><!-- .testimonials-item -->

				<?php endwhile; ?>
				<!-- pager -->
       			<div class="cycle-pager"></div>
				</div><!-- .cycle-slideshow -->
			</div><!-- .testimonials-wrapper -->
			<?php wp_reset_postdata(); ?>

		<?php endif; ?>

	</div><!-- .container -->
</div><!-- .home-section-testimonials -->
