How to call WordPress blog in Magento2 Home page..

Go to \app\design\frontend\<your_vendor_name>/<your_theme_name>/Theme/templates/blog/blog.phtml

Note: I create a blog folder in template 

write the below code


<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance() ?>
<?php $posts = $objectManager->create(‘FishPig\WordPress\Model\ResourceModel\Post\Collection’)
->load(); ?>
<?php if (count($posts) > 0): ?>
<?php foreach($posts as $post): ?>

<a href=”<?php echo $post->getUrl() ?>”><?php echo $this->escapeHtml($post->getPostTitle()) ?></a>
<?php if ($image = $post->getFeaturedImage()): ?>
<a href=”<?php echo $post->getUrl() ?>”>
<img src=”<?php echo $image->getAvailableImage() ?>” src=”<?php echo $this->escapeHtml($post->getPostTitle()) ?>” />
<?php endif; ?>
<p><?php echo $post->getPostExcerpt(40) ?></p></li>
<?php endforeach; ?>
<?php endif; ?>


and call your template to the homepage

{{block class=”Magento\Framework\View\Element\Template” name=”myname” template=”Theme::blog/blog.phtml”}}



Leave a Reply

Your email address will not be published. Required fields are marked *