Reputation: 33
I want to display posts of two or more blogs in my website now am using magpierss-0.72 for fetching the posts and my code is
require_once('rss_fetch.inc');
$url = 'http://rajs-creativeguys.blogspot.com/feeds/posts/default?alt=rss'
/*'http://raghuks.wordpress.com/feed/'*/;
$rss = fetch_rss($url);
foreach ($rss->items as $i => $item ) {
$title = strtoupper ($item['title']);
$url = $item['link'];
$date = substr($item['pubdate'],0,26);
//code to fetch only some text
$desc = '';
$max = 30;
$arr = explode(' ', strip_tags($item['description']));
$l = count($arr);
if($l < $max) $max = $l;
for($j=0;$j<$max;++$j) {
$desc .= $arr[$j] . ' ';
}
$desc .= '.....';
echo "<div class=\"blog\"><a target=\"_blank\" href=$url><h1>$title</h1>$desc<br/><br/>DATED : $date <br/><br/></a></div> ";
if($i == 3) break;
}
Here i can specify only one url of feeds and can fetch but now i want to display posts of two or more blogs Please give me the solution
Thanks in advance
Upvotes: 0
Views: 47
Reputation: 69581
Just use an array and throw in another foreach:
<?php
require_once('rss_fetch.inc');
$urls = array(
'http://rajs-creativeguys.blogspot.com/feeds/posts/default?alt=rss',
' more urls ... ',
);
foreach($urls as $url) {
/*'http://raghuks.wordpress.com/feed/'*/;
$rss = fetch_rss($url);
foreach ($rss->items as $i => $item ) {
$title = strtoupper ($item['title']);
$url = $item['link'];
$date = substr($item['pubdate'],0,26);
//code to fetch only some text
$desc = '';
$max = 30;
$arr = explode(' ', strip_tags($item['description']));
$l = count($arr);
if($l < $max) $max = $l;
for($j=0;$j<$max;++$j)
{
$desc .= $arr[$j] . ' ';
}
$desc .= '.....';
echo "<div class=\"blog\"><a target=\"_blank\" href=$url><h1>$title</h1>$desc<br/><br/>DATED : $date <br/><br/></a></div> ";
if($i == 3) break;
}
}
Upvotes: 1