<?php
/**
 * The template for displaying service image content
 *
 * @package Signify
 */
?>

<?php
$quantity = get_theme_mod( 'signify_service_number', 3 );
$no_thumb = trailingslashit( esc_url ( get_template_directory_uri() ) ) . 'images/no-thumb-140x140.jpg';

for ( $i = 1; $i <= $quantity; $i++ ) {
	$target = get_theme_mod( 'signify_service_target_' . $i ) ? '_blank' : '_self';

	$signify_link = get_theme_mod( 'signify_service_link_' . $i ) ? get_theme_mod( 'signify_service_link_' . $i ) : '#';

	if ( function_exists( 'qtrans_convertURL' ) ) {
		$signify_link = qtrans_convertURL( $signify_link );
	}

	echo '
	<article id="service-post-' . esc_attr( $i ) . '" class="hentry"> <div class="hentry-inner">';

		$signify_title   = get_theme_mod( 'signify_service_title_' . $i );
		$content = get_theme_mod( 'signify_service_content_' . $i );
		$more_button = get_theme_mod( 'signify_service_more_button_text_' . $i );

		$image = get_theme_mod( 'signify_service_image_' . $i ) ? get_theme_mod( 'signify_service_image_' . $i ) : '';

		if ( $image ) {
			echo '
			<div class="post-thumbnail">
			<a href="' . esc_url( $signify_link ) . '" target="' . esc_attr( $target ) . '">
				<img src="' . esc_url( $image ) . '" class="wp-post-image" alt="' . esc_attr( $signify_title ) . '" title="' . esc_attr( $signify_title ) . '">
			</a></div>';
		} else {
			echo '
			<div class="post-thumbnail">
			<a href="' . esc_url( $signify_link ) . '" target="' . esc_attr( $target ) . '">
				<img src="' . esc_url( $no_thumb ) . '" class="wp-post-image" alt="' . esc_attr( $signify_title ) . '" title="' . esc_attr( $signify_title ) . '">
			</a></div>';
		}


		if ( $signify_title || $content || $more_button) {
			echo '
			<div class="entry-container">
				<header class="entry-header">';

				if ( $signify_title ) {
					echo '
					<h2 class="entry-title">
						<a href="' . esc_url( $signify_link ) . '" rel="bookmark" target="' . esc_attr( $target ) . '">' . wp_kses_post( $signify_title ) . '</a>
					</h2>';
				}

				echo '</header>';

				if ( $content || $more_button ) {
					if ( $more_button ) {
						$content .= '<span class="more-button"><a class="more-link" href="' . esc_url( $signify_link ) . '" rel="bookmark" target="' . esc_attr( $target ) . '">' . esc_html( $more_button ) . '</a></span>';
					}

				 	echo '<div class="entry-summary">' . wp_kses_post( $content ) . '</div><!-- .entry-summary -->';
				}



				echo '
			</div><!-- .entry-container -->';
		}

		echo '
		</div>
	</article><!-- .service-post-' . esc_attr( $i ) . ' -->';
} // End for().
