Integrate WordPress feeds in Magento

This article assumes you have already integrated WordPress and Magento and are using v1.2.0 or higher.

 

feedly

On a CMS page or static block

If you want to integrate the feeds inline a cms page or on a static block, then you can use the following code:

{{block="wordpress/feed" feedUrl="http://example.com/blog/feed" template="wordpress/feed.phtml"}}

To set custom options, you can just add it into the command, Eg.

{{block="wordpress/feed" maxChar="150" dateFormat="d-m-Y" feedUrl="http://example.com/blog/feed" template="wordpress/feed.phtml"}}

Available custom options

pTitle="Latest news" – Set the block title
maxChar="150" – Set the maximum length of the description
dateFormat="d-m-Y" – Set the date format (See http://php.net/manual/en/function.date.php)
cssId = "rss_style_id" – Set a special CSS Style ID for the ul tag
pLimit="10" – Set the maximum number of elements displayed

Via XML

If you are permanently integrating the feeds into the design, then you can do it using XML instead.

<reference name="right">
  <block type="wordpress/feed" name="feed.parsefeed" as="rss_feed" template="wordpress/feed.phtml">
    <action method="setFeedUrl"><feedurl>http://example.com/blog/feed</feedurl></action>
  </block>
</reference>

To set custom options, you can just add it into the command, Eg.

<reference name="right">
  <block type="wordpress/feed" name="feed.parsefeed" as="rss_feed" template="wordpress/feed.phtml">
    <action method="setFeedUrl"><feedurl>http://example.com/blog/feed</feedurl></action>
    <action method="setmaxChar"><maxChar>150</maxChar></action>
  </block>
</reference>

Available custom options

<action method="setpTitle"><ptitle>Latest news</ptitle></action> – Set the block title
<action method="setmaxChar"><maxChar>150</maxChar></action>– Set the maximum length of the description
<action method="setdateFormat"><dateFormat>d-m-Y</dateFormat></action>  – Set the date format (See http://php.net/manual/en/function.date.php)
<action method="setcssId"><cssId>rss_style_id</cssId></action> – Set a special CSS Style ID for the ul tag
<action method="setpLimit"><plimit>10</plimit></action> – Set the maximum number of elements displayed
This entry was posted in Magento and tagged , , , , , , , , , , . Bookmark the permalink.

21 Responses to Integrate WordPress feeds in Magento

  1. How can I include content or the sidebar inside the home block? I want to put a list of the latest articles just like the picture you have above, but in the home block.. please help me

    Reply


  2. What do you mean by home block? The content block on the cms home page?

    Reply


    • yes, i made it work with your explanations in this page, thanks.
      Something is weird, when i set the plimit to 4 it shows 5 posts, when i set it to 3 it shows 4 post, i think its counting from zero, so i think it should show what I set.
      I think you have to fix that to avoid confussing people.
      For the rest, THANKS, this is what i was looking for.
      You should create a method to insert the feeds modifying the .phtml template files.
      And a method to actually show the real wordpress widgets in magento.

      Reply


  3. I have succesfully created a nice looking News Ticker modifying your implementation a little bit. If you wanna check it you can visit http://www.naturesgarden.com.ec :) thanks a lot again.

    Reply



  4. Christopher

    I am using magento 1.4.0.1 and wordpress 2.9.2. I have got the blog working, but if I try to use your code for inserting the xml feed in the Magento sidebar, it just falls over. The feed itself works, and I’m using the correct url.

    Any idea why I am getting the following error?

    [code]Warning: Invalid argument supplied for foreach() in /var/www/magento_ayurved_dev/htdocs/app/code/local/Sonassi/Wordpress/Block/Feed.php on line 15[/code]

    I put the XML snippet into design/default/default/templates/local.xml like so:

    [code]
    http://my-website-url.no/blog/feed
    [/code]

    Reply


    • Hi Christopher,

      Given you’ve not provided me with a URL for the site – I can’t really tell you why it isn’t working :(

      Reply


  5. Hello, how can i also show the post thumbnail?
    It only show title, date and excerpt, but i would like to include the post thumbnail please help me

    Thanks in advance

    Reply


  6. Please help me to also show post thumbnail

    Reply


    • Hi Ricardo,

      I’m afraid we don’t have the time to write a guide on this. But if you would like us to develop the functionality, we can do – but it would be for a small fee.

      Reply


  7. Hi Ben,

    I have same error Christopher has. If the wordpress category is empty and have no posts, the feed throws error in magento:
    Warning: Invalid argument supplied for foreach() in /home/np27405/domains/magento3.com/public_html/goa/app/code/local/Sonassi/Wordpress/Block/Feed.php on line 15″;i:1;s:3639:”#0 /home/np27405/domains/magento3.com/public_html/goa/app/code/local/Sonassi/Wordpress/Block/Feed.php(15): mageCoreErrorHandler(2, ‘Invalid argumen…’, ‘/home/np27405/d…’, 15, Array)

    How can i get over this problem? Is there any chance of just display message “No news at this moment” or just empty block?

    Thank You

    Reply


  8. What about customers and wordpress users? Do the two use the same user table or sync in any way? This looks like an awesome modification. I’d like to give it a try but wondering how to maintain the differences in users roles between the two apps. Any hints would be great.

    Thanks for the awesome mod

    Reply


  9. Also have you tried this with WP3 and latest magento 1.4.01?

    Reply



  10. Jonathan

    Hello, ty for sharing.

    I have a question, you have a demo, in that the integration of worpress are in the magento admin, this its a special realise ?

    Or i´m doing something wrong?

    Reply


  11. It will be good to to integrate the feeds inline, on a cms page or on a static block from an SEO point of view as it will increase internal linking? Is that right?

    Reply


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">