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

How To Integrate WordPress Posts on a Magento Site – The Easy Way

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

There are lots of plugins and tutorials out there that try to explain how to integrate WordPress recent blog posts on a Magento site. With all of them you have to either download plugins, establish a wordpress connection, and tweak some Mage code. I have found that if you are just trying to display recent blog posts onto the homepage of your Magento website, there are much easier ways. Just make an snippet that gathers the information from the RSS feed.

I had a client that wanted two display the latest blog post onto the homepage of their Magento site. So I simply went to /app/design/frontend/themename/themename/pages/home.phtml and place in the following code.

<?php
	$channel = new Zend_Feed_Rss('http://example.com/feed');
	$i = 0;
	foreach ($channel as $item):
		if($i < 1) {
			echo '<h5>'.$item->title.'</h5><br/>';
			preg_match_all("/<p>(.*?)<\/p>/si", $item->description, $paragraphs);

			echo $paragraphs[0][0];
			echo $paragraphs[0][1];

			echo "<a href='".$item->link."'' class='readmore'>Read more &gt;&gt;</a>";
			break;
		}
		$i++;
	endforeach;
?>

That’s it, bingo bango. That is a lot easier that trying to make a silly connection.  Just change the Zend_Feed_RSS with your domain name and rss feed location. If you want to show more than one item, then change $i < 1 to whatever number you want.

I hope you find this easier than all the other nonsense.

*As  a note, I made a filter to only display the first to paragraphs.  If you don’t want this you can remove this….

preg_match_all("/<p>(.*?)<\/p>/si", $item->description, $paragraphs);

echo $paragraphs[0][0];
echo $paragraphs[0][1];

and make it this..

echo $item->description

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