<?php
/**
  * The template used for displaying simage/custom lider
  *
  * @package Signify
  */

$quantity = get_theme_mod( 'signify_slider_number', 2 );

$output = '';

for ( $i = 1; $i <= $quantity; $i++ ) {
	$image = get_theme_mod( 'signify_slider_image_' . $i );

	// Check Image Not Empty to add in the slides.
	if ( $image ) {
		$imagetitle = get_theme_mod( 'signify_slider_title_' . $i ) ? get_theme_mod( 'signify_slider_title_' . $i ) : '';

		$signify_title  = '';
		$signify_link   = get_theme_mod( 'signify_slider_link_' . $i );
		$target = get_theme_mod( 'signify_slider_target_' . $i ) ? '_blank' : '_self';

		$signify_title_image = get_theme_mod( 'signify_slider_title_image_' . $i );
		
		$signify_title_image_html = '';

		if ( $signify_title_image ) {
			$signify_title_image_html = '<img src="' . esc_url( $signify_title_image ) . '" title="' . esc_attr( $imagetitle ) . '" alt="' . esc_attr( $imagetitle ) . '"/>';
		}

		$signify_title = '<header class="entry-header"><h2 class="entry-title"><span class="title-image">' . $signify_title_image_html . '</span><span class="title-text">' . esc_html( $imagetitle ) . '</span></h2></header>';

		if ( $signify_link ) {
			$signify_title = '<header class="entry-header"><h2 class="entry-title"><a title="' . esc_attr( $imagetitle ) . '" href="' . esc_url( $signify_link ) . '" target="' . $target . '"><span class="title-image">' . $signify_title_image_html . '</span><span class="title-text">' . esc_html( $imagetitle ) . '</span></a></h2></header>';
		}

		$content = get_theme_mod( 'signify_slider_content_' . $i ) ? '<div class="entry-summary"><p>' . get_theme_mod( 'signify_slider_content_' . $i ) . '</p></div><!-- .entry-summary -->' : '';

		$target        = get_theme_mod( 'signify_slider_target_'. $i ) ? '_blank': '_self';
		$signify_link = get_theme_mod( 'signify_slider_link_' . $i, '#' );
		$text          = get_theme_mod( 'signify_slider_text_' . $i );

		$button = '';

		if ( $text ) :

		$button = '
		<p>
			<a class="more-link" target="' . esc_attr( $target ) . '" href="' . esc_url( $signify_link ) . '"> '. esc_html( $text ) . '
			</a>
		</p>';
		endif;

		$contentopening = '';
		$contentclosing = '';

		// Content Opening and Closing.
		if ( ! empty( $signify_title ) || ! empty( $content ) ) {
			$contentopening = '<div class="slider-content-wrapper"><div class="entry-container">';
			$contentclosing = '</div><!-- .entry-container --></div><!-- .slider-content-wrapper -->';
		}
		
		$output .= '
		<article class="image-slides hentry slider-image images-' . esc_attr( $i ) . ' slides">
			<div class="hentry-inner">	
				<div class="slider-image-wrapper">
					<a href="' . esc_url( $signify_link ) . '" title="' . esc_attr( $imagetitle ) . ' "target="' . $target . '">
						<img src="' . esc_url( $image ) . '" class="wp-post-image" alt="' . esc_attr( $imagetitle ) . '">
					</a>
				</div>
				' . $contentopening . $signify_title . $content . $button . $contentclosing . '
			</div><!-- .hentry-inner -->	
		</article><!-- .slides -->';
	} // End if ().
} // End for().

echo $output;
