Changing number of articles in RSS feed in PHP
-
I’m making a template for a newsletter and I want it to only pull the last 5 articles from my RSS feed. I don’t want to change the number of articles in my RSS feed in WordPress though, because I want 20 showing in some other areas.
Right now I’ve got:
<?php $news = simplexml_load_file('https://mysite.com/rss2'); foreach($news->channel->item as $item) { echo "<a href='$item->link'><strong>" . $item->title . "</strong></a><br />"; echo $item->description; } ?>
Is there a way to only pull 5 articles instead of the whole RSS feed? Like having the RSS feed URL be https://mysite.com/rss2?=last5 (obviously bogus).
Or do I need to rework the foreach loop? Not a PHP programmer, so it took a ridiculous amount of time to figure out this simple one ?? If so, please instruct on how to do a loop for 5 in the example above.
Thanks for any help you can give!
- The topic ‘Changing number of articles in RSS feed in PHP’ is closed to new replies.