增加一个RSS订阅
我们将用 Zend_Feed_RSS 库去分析RSS feed
1.创建一个新的文件叫做tweets.phtml
在app\design\frontend\base\default\template\callouts目录下
2.粘贴下面代码到tweets.phtml
<?php
/**
* @var String $twitterUsername
* change $twitterUsername with your desired username
*/
$twitterUsername = 'packtpub';
/**
* @var String $twitterFeedUrl
* change it with your twitter feed. you will find it at the right side of your twitter page
*/
//由于本地看不到所以换了。
//$twitterFeedUrl = 'http://twitter.com/statuses/user_timeline/17778401.rss';
//这是订阅中国站长站的。
$twitterFeedUrl = 'http://app.chinaz.com/?app=rss&controller=index&action=index';
$tweets = new Zend_Feed_Rss($twitterFeedUrl);
?>
<div class="box base-mini mini-compare-products">
<div class="head">
<h4>Tweet! Tweet!!</h4>
</div>
<?php foreach ($tweets as $key=>$tweet): ?>
<?php if($key <= 4): ?>
<div class="content"><p><?php echo str_replace("$twitterUsername:", "", $tweet->title); ?></p></div>
<?php endif; ?>
<?php endforeach; ?>
</div>
3.登录到你的Magento后台, CMS|Pages|Home|page|Design|Layout Update XML.
添加如下代码
<reference name="right">
<block type="core/template" name="tweets" as="getTweets"
template="callouts/tweets.phtml" translate="label">
<label>Twitter updates</label>
</block>
</reference>
4.刷新页面在首页就可以看到
浙公网安备 33010602011771号