jcadima
2/6/2017 - 10:03 PM

Get latest 2 Wordpress posts in Magento Homepage

Get latest 2 Wordpress posts in Magento Homepage


1) create a frontposts.phtml:
/app/design/frontend/smartwave/granada/template/frontposts/frontposts.phtml


<?php 
$posts = Mage::getResourceModel('wordpress/post_collection')
->addPostTypeFilter('post')
->setOrderByPostDate()
->addIsViewableFilter()
->setPageSize(2)
->load(); ?>
	

<?php	
// GET ONLY THE LATEST 2 POSTS
$permalink = array() ;
$featuredImage = array() ;
$excerpt = array() ;
$post_title = array() ;

foreach($posts as $post) { 
	 if ($image = $post->getFeaturedImage() ) { 
	    $featuredImage[] = $image->getFullSizeImage();
	 } 
	// $featuredImage[] = $post->getFeaturedImage();
	$permalink[] = $post->getPermalink() ;
	$post_title[] = $post->getPostTitle() ;
	$excerpt[] = $post->getPostExcerpt(40) ;
}
	
?>
	
<div class="row">
	
	<div class="container blogframepadding">
	
		
		<div class="col-md-6">
			
			<div class="blogimg1"><img src="<?php echo $featuredImage[0] ; ?>"></div>
			
			<div class="blogtext1">
			<p><strong><?php echo $post_title[0] ; ?></strong></p>
			<p><?php echo $excerpt[0];   ?></p>
			<p><a class="btn btn-black" href="<?php echo $permalink[0] ; ?>">Read more</a></p>			
			</div>	
			
		</div>


	

		<div class="col-md-6 fronttxtleft">
			
			<div class="blogtext2">
			<p><strong><?php echo $post_title[1] ; ?></strong></p>
			<p><?php echo $excerpt[1];   ?></p>
			<p><a class="btn btn-black" href="<?php echo $permalink[1] ; ?>">Read more</a></p>
			</div>
			
			<div class="blogimg2"><img src="<?php echo $featuredImage[1] ; ?>"></div>
			
		</div>
	

	</div>

</div>



2) Call the block above in a normal Magento Page:

{{block type="core/template" template="frontposts/frontposts.phtml"}}