<?php
/**
 * The template for displaying featured image content
 *
 * @package Catch_Store
 */

$quantity = get_theme_mod( 'signify_collection_number', 6 );
$layout   = get_theme_mod( 'signify_collection_layout', 'layout-three' );

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

	$link = get_theme_mod( 'signify_collection_link_' . $i ) ? get_theme_mod( 'signify_collection_link_' . $i ) : '#';

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

	$post_class = '';

	$thumbnail = 'signify-portfolio';

	if ( 'layout-one' == $layout ) {
		$thumbnail = 'signify-slider';
	} elseif ( 'layout-two' == $layout ) {
		if ( 1 === $j % 4 || 0 === $j % 4 ) {
			$post_class = ' featured';
			$thumbnail  = 'signify-collection-large-layout-two';
		}
	} elseif ( 'layout-three' == $layout ) {
		if ( 1 === $j % 4 ) {
			$post_class = ' featured';
		}
	}

	$image = get_theme_mod( 'signify_collection_image_' . $i );

	if ( $image ) {
		$thumb_url = get_theme_mod( 'signify_collection_image_' . $i );
	} else {
		$thumb_url = signify_get_no_thumb_image( $thumbnail, 'src' );
	}

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

			$title   = get_theme_mod( 'signify_collection_title_' . $i );
			$content = get_theme_mod( 'signify_collection_content_' . $i );

			echo '
			<div class="post-thumbnail" style="background-image: url( ' . esc_url( $thumb_url ) . ' )">
				<a class="cover-link" href="' . esc_url( $link ) . '">
				</a>
			</div>';

			if ( $title || $content ) {
				echo '
				<div class="entry-container product-container">';

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

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

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

		echo '
		</div><!-- .hentry-inner -->
	</article><!-- .featured-post-' . esc_attr( $i ) . ' -->';

	if ( $j > 8 ) {
		$j = 0;
	}
} // End for().
