Limiting MagpieRSS entries???

Discussion in 'XML & RSS' started by jawinn, Aug 13, 2006.

  1. #1
    Can some one explain how I control the number of entries from RSS feeds that Magpie will display? The install instructions are pretty vague IMO.

    thx
     
    jawinn, Aug 13, 2006 IP
  2. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #2
    Post your code, I will adapt it.
     
    weppos, Aug 15, 2006 IP
  3. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #3
    Wow thanks. Code below.

    <?php
    //---Code to display RSS feeds using MagpieRSS
    include "magpierss/rss_fetch.inc"; //include the magpierss script
    define('MAGPIECACHEDIR', '/tmp/magpie_cache');
    $url = 'http://website.com/forums/external.php'; //this is the url of the feed, enter your own url here
    $num_items = 2;
    $rss = fetch_rss( $url );

    $items = array_slice($rss->items, 0, $num_items);

    $output = '<a target="_new" href="http://www.website.com/forums">website.com Forums</a><br><br>';
    for ($i = 0; $i < sizeof($rss->items); $i++){
    $output .= '<a target="_new" href="'.$rss->items[$i]['link'].'">'.$rss->items[$i]['title'].'</a><br>';
    $output .= $rss->items[$i]['description'].'<br><br>';
    }
    echo $output;
    //--
     
    jawinn, Aug 16, 2006 IP
  4. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #4
    for ($i = 0; $i < sizeof($rss->items); $i++){
    PHP:
    is a loop that displays all feed items.
    You can change it in this way, from

    for ($i = 0; $i < sizeof($rss->items); $i++){
    $output .= '<a target="_new" href="'.$rss->items[$i]['link'].'">'.$rss->items[$i]['title'].'</a><br>';
    $output .= $rss->items[$i]['description'].'<br><br>';
    } 
    PHP:
    to

    
    $max = 10; // put here the number of items to display
    for ($i = 0; $i < $max; $i++){
    if ($i >= sizeof($rss->items)) break; // exit if current index is >= number of items even if < $max
    $output .= '<a target="_new" href="'.$rss->items[$i]['link'].'">'.$rss->items[$i]['title'].'</a><br>';
    $output .= $rss->items[$i]['description'].'<br><br>';
    } 
    PHP:
    It should fit your need. :)
     
    weppos, Aug 16, 2006 IP
    jawinn likes this.
  5. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #5
    Worked perfectly, thanks.

    One more question, how do I change the time interval that the script polls the rss feed?
     
    jawinn, Aug 16, 2006 IP
  6. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #6
    It dipends how you set the routine that run the script.
    Did you used a cronojob?

    If you are talking about the cache, Magpie has 1 hour cache.
     
    weppos, Aug 16, 2006 IP
  7. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #7
    I don't use a cron job. I just pull the RSS feed from my vB forum.
     
    jawinn, Aug 16, 2006 IP
  8. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #8
    I don't know how often Vb fetch the feed. :(
    I don't know this feature.
     
    weppos, Aug 16, 2006 IP