<?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 $selector = 'alo-content-'.rand(0,999999999); ?>
<?php if ( !$_postCollection->count() ) return; ?>
<div class="<?php /* @escapeNotVerified */ echo $selector?> widget block block-recent-posts" data-bind="scope: 'recent-posts'">
    <div class="block-title">
        <strong><?php echo __($this->getTitle()) ?></strong>
    </div>
    <div class="block-content"
    <?php foreach ($this->getFrontendCfg() as $opt) :?>
        data-<?php /* @escapeNotVerified */ echo $opt ?>='<?php /* @escapeNotVerified */ echo $this->getData($opt) ?>'
    <?php endforeach;?>     
    >
    	<?php foreach ($_postCollection as $_post) { ?>
            <?php $_postUrl = $_post->getPostUrl(); ?>
            <?php $_postName = $block->escapeHtml($_post->getTitle()) ?>
            <div class="item">
                <div class="post-description clearfix">
                    <?php if ($featuredImage = $_post->getFeaturedImage()) { ?>
                    <div class="post-ftimg-hld blog-image al-style-2 image-container">
                        <a href="<?php echo $_postUrl ?>" title="<?php echo $_postName ?>">
                            <img class="lazyload" data-src="<?php /* @escapeNotVerified */ echo $featuredImage ?>" alt="<?php echo $_postName ?>" src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=" />
                        </a>
                    </div>
                    <?php } ?>
					<div class="blog_short_text clearfix">
						<div class="post-info clear">
							<div class="item post-posed-date">
								<span class="value"><?php echo $block->getPostedOn($_post, 'j, n, Y') //'F d, Y' ?></span>
							</div>
                            <div class="content-inner">
    							<a class="post-item-link" href="<?php echo $_post->getPostUrl() ?>">
    								<?php echo $_postName ?>
    							</a>
                                <div class="post-text-hld shortcontent-text clearfix">
                                    <?php echo $block->getShorContent($_post) ?>
                                </div>
    							<a class="post-read-more" href="<?php echo $_postUrl ?>" title="<?php echo $_postName ?>">
    							   <?php echo __('Read more') ?>
    							</a>
                            </div>
						</div>
					</div>
                    
                </div>
                
            </div>

        <?php } ?>
    </div>
</div>
<script type="text/javascript">
    require([
        'jquery',
        'magiccart/slick',
        'alothemes',
        ], function($, slick, alothemes){
            var blog  = $('.<?php echo $selector ?> .block-content');
            if(blog.length) $('head').append(magicproduct(blog, '.item'));
    });
</script>
