Support » Fixing WordPress » Limit fetch_rss to only 5 headlines?

Viewing 11 replies - 1 through 11 (of 11 total)
  • You go to options in the control panel, choose reading, then make alterations in the rss feeds there.

    Good luck with it.



    Thank you LiverpoolLad, but I mean in the fetch_rss function how do I limit the amount of headlines that are picked up? The fetch_rss function syndicates RSS feeds from other websites–not my own. You are talking about how to control my own RSS feed.

    The simple code to embed RSS into our WP blogs is found here:

    It’s simple to use and I can easily add any website’s feed, but I want to know where I can limit it to only displaying maybe 3 or 5 headlines at one time.


    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    You can limit it in the loop immediately following the fetch_rss() line.

    In the given example, instead of using “foreach”, do something more like this:

    for($i=0;$i<5;$i++) {
    echo '<li><a ... blah blah ...



    Ahhh, beautiful. Thank you Otto42! You have solved a big problem!

    I’m trying to do the same thing here, but keep getting syntax errors trying to implement some version of the code above… I keep getting some parsing error that says “Parse error: syntax error, unexpected ‘?’ in…”

    Can someone point me or quote to a working example of full code for HTML/PHP generating a limited set of feeds? If I could see a working, valid loop, it would help…

    Thanks in advance….

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    mattmedia: There’s nothing wrong with the code in the codex. I suggest you check your own code for typos or PHP syntax errors.

    I wholly agree.

    Unfortunately, I’m a designer, not much of a PHP programmer, so my grasp of PHP syntax is admittedly poor.

    I’m not suggesting that this code is wrong — I’m just trying to see an example of this code in the context of a full loop (again, perhaps I’m using the wrong terminology) so I can see how I’m supposed to properly close it, etc…

    For example… my original code ends with

    <?php endforeach; ?>

    Since I’m replacing the “foreach” with this other code, do I need to use another PHP “end” syntax?…

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Possibly. Without seeing your code, it’s hard to say. PHP has multiple ways of doing loops.

    Here’s the example code in the codex converted to a for loop (to only get 5 items):

    <?php require_once(ABSPATH . WPINC . '/rss-functions.php'); ?>
    <?php $rss = fetch_rss(''); ?>
    <?php for($i=0;$i<5;$i++) {
    $item=$rss->items[$i]; ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    <?php } ?>

    This is pretty basic stuff, I’d really suggest picking up a couple of good beginner PHP and/or generic programming books, yeah? Might be more useful.

    Thanks. This is very helpful. I’m learning PHP along with WordPress stuff all at once, so I’m still getting my head around the syntax. Appreciate the nudge in the right direction…

    Thanks for that snippet of example code, Otto.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Limit fetch_rss to only 5 headlines?’ is closed to new replies.