<?php
/**
 * Template part for displaying posts with the "lateral" display
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Tattoopress
 * @version 3.3.4
 */

extract( wp_parse_args( $template_args, array(
	'post_excerpt_length' => 'shorten',
	'post_display_elements' => 'show_thumbnail,show_date,show_text,show_author,show_category',
	'post_alternate_thumbnail_position' => '',
	'index' => 0,
) ) );

$even_class = '';

$even = ( $index % 2 === 0 );
$odd = ( $index % 2 !== 0 );



if ( $odd && $post_alternate_thumbnail_position ) {
	$even_class = 'odd';
} elseif ( $even && $post_alternate_thumbnail_position ) {
	$even_class = 'even';
}

$post_display_elements = tattoopress_list_to_array( $post_display_elements );
$show_thumbnail = ( in_array( 'show_thumbnail', $post_display_elements ) );
$show_date = ( in_array( 'show_date', $post_display_elements ) );
$show_text = ( in_array( 'show_text', $post_display_elements ) );
$show_author = ( in_array( 'show_author', $post_display_elements ) );
$show_category = ( in_array( 'show_category', $post_display_elements ) );
$show_tags = ( in_array( 'show_tags', $post_display_elements ) );
$show_extra_meta = ( in_array( 'show_extra_meta', $post_display_elements ) );
?>
<article <?php tattoopress_post_attr(); ?>>
	<div class="entry-box">
		<div class="entry-container <?php echo esc_attr( $even_class ); ?>">

			<?php if ( $odd || ! $post_alternate_thumbnail_position ) : ?>
				<?php if ( $show_thumbnail ) : ?>
					<?php if ( tattoopress_has_post_thumbnail() || tattoopress_is_instagram_post() ) : ?>
						<div class="entry-image">
							<?php if ( $show_category ) : ?>
								<a class="category-label" href="<?php echo tattoopress_get_first_category_url(); ?>"><?php echo tattoopress_get_first_category(); ?></a>
							<?php endif; ?>
							<div class="entry-lateral-cover">
								<a href="<?php the_permalink(); ?>">
								<?php
									echo tattoopress_background_img( array(
										'background_img_size' => 'large',
										'placeholder_fallback' => true,
									) );
								?>
								</a>
							</div><!-- entry-cover -->
						</div><!-- .entry-image -->
					<?php endif; ?>
				<?php endif; ?>
			<?php endif ?>
			<div class="entry-summary">
				<div class="entry-summary-inner">
					<?php if ( ! is_sticky() && $show_date ) : ?>
						<span class="entry-date">
							<?php tattoopress_entry_date(); ?>
						</span>
					<?php endif; ?>
						<?php
							if ( is_sticky() && ! is_paged() ) {
								echo '<span class="sticky-post" title="' . esc_attr( __( 'Featured', 'tattoopress' ) ) . '"></span>';
							}
						?>
						<?php the_title( '<h2 class="entry-title"><a class="entry-link" href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
					<?php if ( $show_text ) : ?>
						<div class="entry-excerpt">
							<?php if ( 'full' === $post_excerpt_length ) : ?>
								<?php echo tattoopress_sample( get_the_excerpt(), 1000 ); ?>
							<?php else : ?>
								<?php echo tattoopress_sample( get_the_excerpt(), tattoopress_get_excerpt_lenght() ); ?>
							<?php endif; ?>
							<span class="read-more">
								<a href="<?php the_permalink(); ?>" class="<?php echo esc_attr( apply_filters( 'tattoopress_more_link_button_class', '' ) ); ?>">
								<?php echo tattoopress_kses( apply_filters( 'tattoopress_read_more_text', esc_html__( 'Read more', 'tattoopress' ) ) ); ?>
								</a>
							</span>
						</div><!-- .entry-excerpt -->
					<?php endif; ?>
					<?php if ( $show_category && ( ! tattoopress_has_post_thumbnail() || ! $show_thumbnail ) ) : ?>
						<div class="entry-category-list">
							<?php echo get_the_term_list( get_the_ID(), 'category', esc_html__( 'In', 'tattoopress' ) . ' ', esc_html__( ', ', 'tattoopress' ), '' ) ?>

						</div>
					<?php endif; ?>
				</div><!-- .entry-summary-inner -->
				<?php if ( $show_author || $show_tags || $show_extra_meta || tattoopress_edit_post_link( false ) ) : ?>
					<div class="entry-meta">
						<?php if ( $show_author ) : ?>
							<?php tattoopress_get_author_avatar(); ?>
						<?php endif; ?>
						<?php if ( $show_tags ) : ?>
							<?php tattoopress_entry_tags(); ?>
						<?php endif; ?>
						<?php if ( $show_extra_meta ) : ?>
							<?php tattoopress_get_extra_meta(); ?>
						<?php endif; ?>
						<?php tattoopress_edit_post_link(); ?>
					</div><!-- .entry-meta -->
				<?php endif; ?>
			</div><!-- .entry-summary -->
			<?php if ( $even && $post_alternate_thumbnail_position ) : ?>
				<?php if ( $show_thumbnail ) : ?>
					<?php if ( tattoopress_has_post_thumbnail() || tattoopress_is_instagram_post() ) : ?>
						<div class="entry-image">
							<?php if ( $show_category ) : ?>
								<a class="category-label" href="<?php echo tattoopress_get_first_category_url(); ?>"><?php echo tattoopress_get_first_category(); ?></a>
							<?php endif; ?>
							<div class="entry-lateral-cover">
								<a href="<?php the_permalink(); ?>">
								<?php
									echo tattoopress_background_img( array(
										'background_img_size' => 'large',
										'placeholder_fallback' => true,
									) );
								?>
								</a>
							</div><!-- entry-cover -->
						</div><!-- .entry-image -->
					<?php endif; ?>
				<?php endif; ?>
			<?php endif ?>
		</div><!-- .entry-container -->
	</div><!-- .entry-box -->
</article><!-- #post-## -->