<?php
/**
 * Copyright © 2015 Ihor Vansach (ihor@magefan.com). All rights reserved.
 * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
 *
 * Glory to Ukraine! Glory to the heroes!
 */
?>
<?php
/**
 * Blog sidebar recent posts template
 *
 * @var $block \Magefan\Blog\Block\Sidebar\Recent
 */
?>

<?php
	$_postCollection = $block->getPostCollection();
?>
<?php if ($_postCollection->count()) { ?>
	<?php foreach ($_postCollection as $_post) { ?>
		<?php $post_date = $_post->getData("publish_time");?>
		<div class="post-slide">
		  <div class="post-item post-title-simple">
				<?php if($post_image = $_post->getFeaturedImage()): ?>
		    <a href="<?php echo $_post->getPostUrl() ?>" class="m-b-md d-block">
					<img src="<?php echo $post_image; ?>" alt=""/>
		    </a>
				<?php endif; ?>
				<div class="post-content">
			    <div class="post-date">
						<span class="day"><?php echo date("j", strtotime($post_date)); ?></span>
						<span class="month"><?php echo date("M", strtotime($post_date)); ?></span>
						<time><?php echo date("M j, Y", strtotime($post_date)); ?></time>
					</div>
			    <h4><a href="<?php echo $_post->getPostUrl() ?>" ><?php echo $block->escapeHtml($_post->getTitle()) ?></a></h4>
					<div class="post-meta m-b-sm d-none"><?php echo date("M j, Y", strtotime($post_date)); ?></div>
			    <div>
						<?php if($_post->getShortContent()):?>
				      <p class="post-excerpt">
								<?php
								$length = 88;
								$shortContent = $_post->getShortContent();
								echo $shortContent = (strlen($shortContent) > $length) ? substr($shortContent,0,$length).'...' : $shortContent;?>
				        <a class="read-more" href="<?php echo $_post->getPostUrl() ?>"><?php echo __("read more");?> <i class="fas fa-angle-right"></i></a>
				      </p>
						<?php endif;?>
			    </div>
				</div>
		  </div>
		</div>
	<?php } ?>
<?php } ?>
