<?php $theme_options_data = theme_options_data(); ?>

<?php $categories = get_the_terms( get_the_ID(), 'recipe_category' ) ?>

<?php
if ( is_archive() && get_post_type() == 'recipe' ) {
	if ( isset( $theme_options_data['thim_recipe_cate_number_column'] ) ) {
		$number_column = $theme_options_data['thim_recipe_cate_number_column'];
	} else {
		$number_column = 4;
	}
} else {
	$number_column = 3;
}
?>

<div class="item item-column-<?php echo esc_attr( $number_column )?><?php if ( $categories ) {
	foreach ( $categories as $category ) {
		echo ' ' . $category->slug;
	}
} ?>">
	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

		<?php
		$image   = wp_get_attachment_image( get_post_thumbnail_id( get_the_ID() ), 'full' );
		$name    = get_the_title();
		$details = thim_get_recipe_details( $id );
		?>
		<div class="recipe-image">
			<?php
			if ( function_exists( 'thim_get_recipe_details' ) ) {
				$video_url = $details['video_url'];
				if ( $video_url ) {
					// Get the video URL from custom field
					$videoID = substr( $details['video_url'], 32 );
					// Echo out the thumbnail, give it height and weight and set the alternate description to post title
					echo '<img class="video-img" src="http://i1.ytimg.com/vi/' . $videoID . '/maxresdefault.jpg" alt="' . esc_attr( get_the_title() ) . '">';
					echo '<div class="wrap-play"><div class="play-button"><a  href="' . esc_url( get_the_permalink() ) . '"><i class="fa fa-play"></i></a></div></div>';

				} else { // else use the standard featured image
					$data_video = get_post_meta( get_the_ID(), 'thim_custom_attachment', true );
					if ( $image ) {
						$data_video = get_post_meta( get_the_ID(), 'thim_custom_attachment', true );
						if ( $data_video ) {
							echo wp_get_attachment_image( get_post_thumbnail_id( get_the_ID() ), 'full' );
							echo '<div class="wrap-play"><div class="play-button"><a  href="' . esc_url( get_the_permalink() ) . '"><i class="fa fa-play"></i></a></div></div>';
						} else {
							echo wp_get_attachment_image( get_post_thumbnail_id( get_the_ID() ), 'full' );
						}
					} else {
						echo '<p class="reporting">' . esc_html__( 'Have no featured image. You should set one', 'cakeart' ) . '</p>';
					}
				}
			}
			?>
			<a class="link" href="<?php echo esc_url( get_the_permalink() ); ?>"></a>
			<?php if ( is_plugin_active( 'comment-rating-stars/comment-star-reviews.php' ) ) : ?>
				<div class="rating-star">
					<div class="rating-star-wrap">
						<?php echo csr_get_overall_rating_stars( get_the_ID() ); ?>
					</div>
				</div>
			<?php endif; ?>
		</div>
		<div class="recipe-name">
			<a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_attr( $name ); ?></a></div>

		<?php echo sprintf(
			'<span class="author vcard">' . esc_html__( 'By: ', 'cakeart' ) . '<a class="url fn n link-post-on" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
		);

		echo '<span class="cook-time"><i class="fa fa-clock-o"></i>&nbsp;&nbsp;' . esc_html( thim_recipe_time( $details['cook_time'] ) ) . '</span>';
		?>

	</article>
	<!-- #post-## -->
</div>