Jigowatt

Display WordPress blog posts in a Magento page

Posted by Jay on Thursday, November 12th, 2009 at 1:08 pm

Due to Magentos lack of a solid news system and WordPress’ general awesomeness we often find ourselves integrating the two which is a fairly painless process. Once integrated, one of the first and most important things we want to do is display some posts from the WordPress side of the web site, be it news, blog posts or articles inside a Magento page. The easiest way to do this is to utilise the feed functionality built in to WordPress. We use the following code to do so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<ul>
<?php
$channel = new Zend_Feed_Rss('http://www.jigowatt.co.uk/feed'); // Your RSS Feed Address
$limit_result = 3; // The amount of latest items to output.
$i = 0;
foreach ($channel as $item):
if ($i < $limit_result) {
echo '<li>';
echo '<a href="' . $item->link . '">' . $item->title . '</a><br />';
echo $item->description . '<br /><br />';
echo '</li>';
$i++;
}
endforeach; ?>
</ul>

Paste the above code into any page you want to display WordPress posts on.

The only lines you really need to pay attention to are 3 and 4. In line 3 you simply replace “http://www.jigowatt.co.uk/feed” with your own feed URL and on line 4 you can set the amount of posts to be displayed.

This code will actually work with any feed, be it WordPress, Joomla, Drupal or any other CMS.

Enjoy!

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Design Float
  • email
  • StumbleUpon
  • Twitthis

Related posts:

2 Responses to “Display WordPress blog posts in a Magento page”

  1. Ishan says:

    This is not a proper solution, this requires Zend which is generally not available on servers.

    You should make some other code to make it work properly.

    • Chris says:

      @Ishan

      The majority of servers now come pre-configured with Zend as it’s an extremely useful and widely used framework, certainly on Plesk / WHM based servers if it isn’t installed it’s a very simple click through process to install.

      However, to avoid this problem you can find freely available RSS Classes across the web that place RSS Feeds into Arrays, this is all thats required to run a foreach function.

Leave a Reply