School of Net


Usando Zend_Feed no site! -

Filed under: Desenvolvimento — Tags: , , — Wesley Willians @ 14:30

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://www.schoolofnet.com.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)

ÚLTIMOS POSTS EM NOSSO BLOG

    posts as $post): ?>
  • - ()

Acredito que esse código é simples. Caso tenham alguma dúvida quanto a isso, por favor, façam um comentário.


1 Comentário »

  1. Parabéns pelo post, utilizei no meu site e deu certo.

    Comentário by Jorge — 08/01/2010 @ 20:18

RSS feed for comments on this post. TrackBack URL


Leave a comment