Na home page do site de pré-lançamento da SON (School of Net), iremos exibir os últimos posts deste blog.
Para isso tivemos que utilizar o Zend_Feed.
Veja abaixo como utilizamos isso:
No indexController.php
public function indexAction() {
$filter = new Zend_Filter_StripTags ( );
$this->view->use_content = true;
try {
$blogSon = Zend_Feed::import ( 'http://blog.schoolofnet.com/index.php/feed/' );
// Loop through the items in the feed
$items = array ( );
$i = 0;
foreach ( $blogSon as $item ) {
if ($i < 5) {
$items [] = array (
'title' => $item->title (),
'link' => $item->link (),
'description' => $filter->filter($item->description ()),
'pubDate' => new Zend_Date($item->pubDate ())
);
};
$i ++;
}
$this->view->rss = $blogSon;
$this->view->posts = $items;
}
catch ( Zend_Feed_Exception $e ) {
// feed import failed
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit ();
}
Na View (index.phtml)
<h3>ÚLTIMOS POSTS EM NOSSO BLOG</h3> <div id="blogcontent"> <ul> <?foreach($this->posts as $post): ?> <li><a href="<?=$post['link']?>" target="_blank" title="<?=$post['description']?>"><?=$post['title']?> - (<?=$post['pubDate']?>)</a></li> <?endforeach; ?> </ul> </div>
Acredito que esse código é simples. Caso tenham alguma dúvida quanto a isso, por favor, façam um comentário.



















