I am trying to posts blogs on the homepage (this is Magento 2).
So I have the following template, called blog-homepage.phtml, stored at app/design/frontend/XX/theme-default/Aheadworks_Blog/templates/blog-homepage.phtml:
<?php
/* @var $block \Aheadworks\Blog\Block\PostList */
?>
<?php
$posts = $block->getPostCollection();
?>
<?php if ($posts->getSize()): ?>
<div class="aw-blog-posts">
<?php foreach ($posts as $post): ?>
<?php echo $block->getItemHtml($post) ?>
<?php endforeach; ?>
</div>
<?php if ($block->getPagerHtml()): ?>
<div class="aw-blog-pagination"><?php echo $block->getPagerHtml(); ?></div>
<?php endif ?>
<?php else: ?>
<div class="message info empty">
<div><?php echo __('No posts.') ?></div>
</div>
<?php endif; ?>
~
The issue is that I get all posts that have been created, and I would like to display only the most recent three.
Is there a way to achieve this? Thanks for your collaborations
I found the answer: 1. To copy the template, that comes with the extension, to the custom theme. 2. To adjust it so that it only shows three or four posts -this can be achieved by applying some php code-; if not adjusted, the template would show all posts created since the beginning. 3. To place the template on the homepage (via xml or at the backend on the cms page). Easy and effective solution. It worked for me.