Do You Want to Learn Marketing or Coding? Do You Want to Learn Marketing or Coding?

How to Display WordPress blog posts with Featured Images on Magento’s Homepage using FishPig module

Share on facebook
Share on twitter
Share on linkedin

Hi there, this tutorial assumes you already have FishPig’s magento to wordpress module already installed and configured. Once you have that done open up your homepage theme and type in this code where you want the blog posts to appear

 <?php echo  $this->getLayout()->createBlock('wordpress/sidebar_widget_posts')->setPostCount(6)->setTemplate('wordpress/sidebar/widget/homepost.phtml')->toHtml(); ?>

Next go to your app/design/frontend/yourtheme/yourtheme/wordpress/sidebar/widget/ folder and place in this code:

<?php $posts = $this->getPosts() ?>
<?php if (count($posts) > 0): ?>
			<?php foreach($posts as $post): ?>
					  <?php if ($featuredImage = $post->getFeaturedImage()){ ?>
					    <a href="<?php echo $post->getPermalink() ?>">
					    	 <div class="blog">
					        	<img src="<?php echo $featuredImage->getLargeImage();?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
					<?php }  ?>
			<?php endforeach; ?>

<?php endif; ?>

That code will display a blog’s featured image if it has one.

You can also add more too it but using functions like:

$post->getPostTitle(); // Post title
$post->getPostDate(); // Post date
$post->getPostDate(); // Post date

If you want to put more content in the foreach loop.

Finally if you want to display a different image size use these instead:


Simply choose one and place it instead of getLargeImage in the code posted above.

Finally, the custom featured image code would look like this, you would need to set your custom image size in your wordpress function file, but we assume you did that already. To call up the custom image size you use this code:

getImageByType($type = 'typenamehere');

I Really Need

Reviewing nerdy stuff is expensive.

Consider clicking on this ad & buying that item you REALLY wanted from Amazon.

It helps a ton!

Leave Your Thoughts