Latest News in Magento

Featured Image

You would like to have a eCommerce power of Magento, but also have a blog to empower your business? In this case, you probably know that Magento doesn’t have some article manager in the box. Many clients seek for supplementary solution like WordPress to accomplish this goal. Ok, so you created a blog on same or different domain and you would like those articles to appear somewhere in Magento (probably sidebar). This article will explain how to do it.

Step 1

Let’s create a file called latest_news.phtml in app/design/frontend/default/[your_theme]/template/callouts/latest_news.phtml
Now we will create a PHP block that will display the list of articles from RSS feed. We will use Inchoo RSS for demonstration purposes. In your scenario, replace it with your own valid RSS URL.

< ?php $channel = new Zend_Feed_Rss('http://feeds.feedburner.com/Inchoo'); ?>
 
<div class="block block-latest-news">
<div class="block-title">
<h2>< ?php echo $this->__('Latest News') ?></h2>
</div>
<div class="block-content">
<ol id="graybox-latest-news">
< ?php foreach ($channel as $item): ?>
<li><a href="<?php echo $item->link; ?>">< ?php echo $item->title; ?></a></li>
< ?php endforeach; ?>
</ol>
</div>
</div>

Step 2
Now, we should decide where to place it. I assume you already know how Magento blocks and references work. Let’s assume you would like to place it in right column by default for whole catalog. In this case open your app/design/frontend/default/[your_theme]/layout/catalog.xml file and under “default” tag update “right” reference with something similar.

<reference name="right">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
<block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"/>
<block type="core/template" name="right.latest.news" template="callouts/latest_news.phtml"/>
</reference>

That’s it. You should be able to see the list of articles from RSS feed with the URLs. Hope this will help someone.


About Tomislav Bilic

Founder and CEO

Tomislav is a founder and CEO at Inchoo. Enjoys traveling - especially quick getaways, traditional cuisine (from most cultures), good wine and strong rakija.

Read more posts by Tomislav / Visit Tomislav's profile

60 comments

  1. How can we use “_buildEntryCache” method along with Zend_Feed_Rss for better performance??
    is there any alternate way to cache result for X time?

  2. Will this go into cache of the system?
    Do I need to do something to cache it?
    Because if each hit It reloads the feed it will be quite a load…

    Thanks!

  3. Thanks. I`m a newb at magento but i managed to get it to work in the sidebar on all pages.
    Limited to 3 articles tho and 100 characters so it wont get big :d
    thanks again

  4. Sounds like a syntax error – paste what you have written and someone will be able to help.

  5. When i include this code.. home page content disappears .. and when i remove this code (specially 1st line) it shows back..

  6. Also you need to do a find and replace and change all [ to to ]

    Also would just like to say this site is awesome, I have learnt so much about Magento in such a short space of time and most of that knowledge has come from this site.
    Keep up the good work.

  7. Just went through the whole post, Thank you to all who contributed. This made it a lot easer for a classic asp dev like me.
    just thought i would make this easer for every new viewer.

    [?php $channel = new Zend_Feed_Rss('http://feeds.feedburner.com/Inchoo'); ?]
    [div id="rss-block-container"]
    [div class="rss-block-title"]
    [h2][?php echo $this-]__('Latest News') ?][/h2]
    [/div]
    [div id="rss-content"]
    [ol id="rss-content"]
    [?php $counter = 0; ?]
    [?php foreach ($channel as $item): ?]
    [li id="rss-content"][p][strong][a href="[?php echo $item-]link; ?]"][?php echo $item-]title; ?][/a][/strong][/p][?php echo substr($item-]description,0,150); ?]....[p][strong][a href="[?php echo $item-]link; ?]"]Read More[/a][/strong][/p][p][strong][?php echo $item-]pubDate; ?][/strong][/p][/li]
    [?php if(++$counter == 3) {break;}?]
    [?php endforeach; ?]
    [/ol]
    [/div]
    [/div]

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=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.