Adding a WordPress Feed in Magento
Right, it has been a while since I posted on the green acorn web development blog. So today I am going to publish a quick tutorial. Lately I have been working on a Magento site with WordPress as the blogging platform. Normally to load WordPress in an external system, you simply require wp-load.php which gives you access to all the WordPress functions. However, try and do this in Magento and it will give you all sorts of problems.
The solution is simple. Go to feedburner.google.com and sign in / up with a Google account. Simply follow the instructions to set up a Feedburner RSS feed by pasting in your WordPress url. Once you have done this Feedburner should give you a url like the example below:
Adding the WordPress Feed to Magento
Next I will be making use of the RSS channel class which is a part of the Zend Framework. In your Magento template file, simply copy and paste the below code. Replace the Feedburner url with the one provided and set the amount of new articles you would like to display.
<div class="news"> <?php $channel = new Zend_Feed_Rss('http://feeds.feedburner.com/co/sqFx'); ?> <?php $i = 0; ?> <h1><?php echo $this->__('Latest News') ; ?></h1> <?php foreach ($channel as $item): ?> <?php if ($i < 3) : // number of articles ?> <h2><a title="<?php echo $item->title; ?>" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a></h2> <p><?php echo $item->description(50); ?> <a title="<?php echo $item->title; ?>" href="<?php echo $item->link; ?>">[Read More..]</a></p> <?php endif; ?> <?php $i++; ?> <?php endforeach; ?> </div>
Now reload your page and you should see a Latest News feed from your WordPress Blog. I hope you found this quick tutorial useful.