<?php if (is_post_type('post')) { ?>
	<article>
		<a href="<?php echo the_permalink(); ?>">
			<div class="img">
				<div class="thumb" style="background-image: url(<?php echo get_the_post_thumbnail_url() ?>);"></div>
				<?php $post_cat = get_the_category();
				if ( $post_cat ) {
					echo '<span class="tag">'.$post_cat[0]->name.'</span>'; 
				} ?>
			</div>
			<div class="meta">
				<div class="data"><?php echo get_the_date(); ?>   •   By <?php echo get_the_author(); ?></div>
				<h1 class="title"><?php echo get_the_title(); ?></h1>
				<p class="excerpt"><?php echo excerpt(15); ?></p>
			</div>
		</a>
	</article>
<?php } else if (is_post_type('review')) { ?>
	<?php 
	$categories = get_the_terms( $post->ID , 'review_category' );
	$post_class = '';
	$attributes = get_the_terms( $post->ID , 'other_attributes' );
	foreach($categories as $category){
		$post_class .= ' '.$category->slug;
	}
	foreach($attributes as $attribute){
		$post_class .= ' '.$attribute->slug;
	}
	$post_class .= ' rating_'.str_replace('.','',get_field('rating'));
	?>
	<article class="review-item row animated fadeInUp <?php echo $post_class; ?>">
		<div class="review-item-meta">
			<?php $companies = get_field('company');

			foreach( $companies as $company ) :?>
				<div class="logo">
					<img src="<?php echo get_field('logo',$company->ID); ?>">
				</div>
				<div class="rating">
					<span class="stars">
						<?php 
						$rating = get_field('rating');
						for($stars=0;$stars<$rating;$stars++) {
							if (($stars+0.5)==$rating) {
								echo '<span class="half"></span>';
								$exclude = 1;
							} else {
								echo '<span class="full"></span>';
								$exclude = 0;
							}
						}
						for($stars=$exclude;$stars<5-$rating;$stars++) {
							
                        if (($stars+0.5)==$rating) {
								echo '<span class="half"></span>';
							} else {
								echo '<span class="empty"></span>';
							}
						} ?>
					</span>
					<?php echo get_field('rating') ?> out of 5
				</div>
				<div class="attributes">
					<ul>
						<?php 
						foreach($categories as $category){
							echo '<li>'.$category->name.'</li>';
						}
						foreach($attributes as $attribute){
							echo '<li>'.$attribute->name.'</li>';
						}
						?>
					</ul>
				</div>
				<?php 
			endforeach; ?>
		</div>
		<div class="review-item-content">
			<h1><?php echo get_the_title(); ?></h1>
			<div class="excerpt"><?php $description = trim(get_field('description')); if (strlen($description) !== 0) { echo '<p>'.$description.'</p>'; } else { echo content(100); } ?><div class="read-more">Read More</div></div>
			<a href="<?php echo the_permalink(); ?>" class="underline show">Review Solution</a>
		</div>
	</article>
<?php } ?>