<?php
/**
 * The template for displaying a grid item.
 *
 * @package WordPress
 * @subpackage Edition
 * @since Edition 1.0
 */
global
$tw_section, // section object
$grid_size, // grid size
$post;		 // section object

$section_id    = get_the_ID($post);  // section id
$tw_categories = ag_get_cats_array(3);   // get all post categories
$post_type     = get_post_type();

$thumbnail_size = 'half';
$thumbnail_size = ($grid_size == 'fullgrid') ? 'big' : $thumbnail_size;
if ($grid_size == 'related') {
	$thumbnail_size = 'related';
} ?>

<div class="<?php if ( isset($tw_categories[0]->term_id) ) { echo 'highlight_category_' . $tw_categories[0]->term_id; } ?> <?php echo (has_post_thumbnail()) ? 'has-thumbnail' : 'no-thumbnail'; ?> <?php echo esc_attr( $grid_size );?> grid-item">
	<div class="isobrick-inner">
		<?php
			the_post_thumbnail($thumbnail_size);
		?>

		<?php echo themewich_review_circle('none', false); ?>

		<?php if ( 'post' == $post_type ) : ?>
			<span class="thumboverdate">
				<i class="fa fa-bookmark"></i>
				<?php themewich_date('human'); ?>
			</span>
		<?php else: ?>
			<?php if ( function_exists( 'wc_get_template' ) ) : ?>
				<span class="thumboverdate">
					<?php wc_get_template( 'loop/price.php' ); ?>
				</span>
			<?php endif; ?>
		<?php endif; ?>

		<div class="thumbovertext">
			<div class="badge">
				<?php echo ag_get_cats(3); ?>
			</div>
			<h2 class="title">
				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
					<?php
						$title = get_the_title();
						if (strlen($title) >= 75) {
						     $title = mb_substr($title, 0, 75) . "... ";
						}
						echo wp_kses_post( $title );
					?>
				</a>
			</h2>

			<?php if ( 'post' == $post_type ) : ?>
				<?php preg_match('/<!--more(.*?)?-->/', $post->post_content, $matches); ?>
				<a class="button outline" href="<?php the_permalink(); ?>"  title="<?php the_title_attribute(); ?>">
					<?php
						if ( isset($matches[1]) && $matches[1] ) {
							echo esc_html( $matches[1] );
						} else {
							_e('Read More', 'themewich');
						}
					?>
				</a>
			<?php endif; ?>

		</div>

		<a class="brick-thumb-link" href="<?php the_permalink(); ?>"  title="<?php the_title_attribute(); ?>">
			<?php the_title(); ?>
		</a>
	</div>
</div>