Skip to content Skip to sidebar Skip to footer

Limit The Number Of Rss Feed To Fetch

I need help with the code of the RSS reader i'm testing on my site, the script work fine but it show 20 feed and i wanted to limit it to a number i set (like 3 or 6 for example). T

Solution 1:

Just add counter and a break in the loop if you want to limit the results:

<ul><?php$i = 0; // 3 - 6// Print all the entriesforeach($entriesas$entry) { 
    $i++;
?><li><ahref="<?=$entry->link ?>"><?=$entry->title ?></a> (<?= parse_url($entry->link)['host'] ?>)
        <p><?= strftime('%m/%d/%Y %I:%M %p', strtotime($entry->pubDate)) ?></p><p><?=$entry->description ?></p><imgsrc="<?=$entry->children('media', true)->content->attributes()->url ?>"alt="" /></li><?phpif($i === 3) break;
} 
?></ul>

Or just cut the array using array_splice:

<ul><?php$entries = array_splice($entries, 0, 3);
// Print all the entriesforeach($entriesas$entry) { ?><li><ahref="<?=$entry->link ?>"><?=$entry->title ?></a> (<?= parse_url($entry->link)['host'] ?>)
        <p><?= strftime('%m/%d/%Y %I:%M %p', strtotime($entry->pubDate)) ?></p><p><?=$entry->description ?></p><imgsrc="<?=$entry->children('media', true)->content->attributes()->url ?>"alt="" /></li><?php } ?></ul>

Post a Comment for "Limit The Number Of Rss Feed To Fetch"