LastRSS Limit to One Feed

Discussion in 'XML & RSS' started by Emory, Jul 2, 2006.

  1. #1
    I'm using LastRSS to display RSS feeds from sites. The trouble is that some feeds contain long lists of links. I don't want to clutter a page with all of the links. Does anyone have a solution for limiting the display to just the first link, title and description?
     
    Emory, Jul 2, 2006 IP
  2. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #2
    With links do you mean feed items?
    If yes, since lastRSS returns an associative array with RSS items, just select the first array index ( 0 ).
     
    weppos, Jul 2, 2006 IP
  3. Emory

    Emory Peon

    Messages:
    82
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, I do mean feed items.

    I tried this:

        $item = $rs->rssarray['items'][0]; { 
            echo "\t<li> title=\"$item[description]\" href=\"$item[link]\">".$item['title']."</a></li>\n"; 
            }
    PHP:
    It displays just one bullet point with no text. No error message. Any idea what's wrong? Thanks.
     
    Emory, Jul 3, 2006 IP
  4. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #4
    If you print

    print_r($rs->rssarray);
    PHP:
    what do you see?
    Do you see any item?
     
    weppos, Jul 4, 2006 IP
  5. Emory

    Emory Peon

    Messages:
    82
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't see any items when using that line.

    Here's the code currently being used:

    <?php 
    // include lastRSS 
    include "lastRSS.php"; 
    // Create lastRSS object 
    $rss = new lastRSS; 
    // Set cache dir and cache time limit (1200 seconds) 
    // (don't forget to chmod cache dir to 777 to allow writing) 
    $rss->cache_dir = './temp'; 
    $rss->cache_time = 1200; 
    // Try to load and parse RSS file 
    if ($rs = $rss->get('http://www.clickfire.com/viewpoints/blog/feed/')) { 
        // Show last published articles (title, link, description) 
        echo "<ul>\n"; 
        foreach($rs['items'] as $item) { 
            echo "\t<li> <a title=\"$item[description]\" href=\"$item[link]\">".$item['title']."</a></li>\n"; 
            }
        echo "</ul>\n"; 
        } 
    else { 
        echo "Error: It's not possible to reach RSS file...\n"; 
    } 
    ?> 
    PHP:
     
    Emory, Jul 4, 2006 IP
  6. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #6
    <?php 
    // include lastRSS 
    include "lastRSS.php"; 
    // Create lastRSS object 
    $rss = new lastRSS; 
    // Set cache dir and cache time limit (1200 seconds) 
    // (don't forget to chmod cache dir to 777 to allow writing) 
    $rss->cache_dir = './temp'; 
    $rss->cache_time = 1200; 
    // Try to load and parse RSS file 
    if ($rs = $rss->get('http://www.clickfire.com/viewpoints/blog/feed/')) { 
    print_r($rs);
    /*
        // Show last published articles (title, link, description) 
        echo "<ul>\n"; 
        foreach($rs['items'] as $item) { 
            echo "\t<li> <a title=\"$item[description]\" href=\"$item[link]\">".$item['title']."</a></li>\n"; 
            }
        echo "</ul>\n"; 
    */
        } 
    else { 
        echo "Error: It's not possible to reach RSS file...\n"; 
    } 
    ?> 
    PHP:
    Could you print here the output?
     
    weppos, Jul 4, 2006 IP
  7. Emory

    Emory Peon

    Messages:
    82
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It doesn't output anything with the above. Could it be because I'm using version lastRSS 0.9.1 class?
     
    Emory, Jul 4, 2006 IP
  8. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #8
    I don't really know, I've never used lastRSS.
    Try using Magpie RSS. http://magpierss.sourceforge.net/

    <?php 
    
    $url = 'http://www.clickfire.com/viewpoints/blog/feed/';
    
    require('rss_fetch.inc');
    $rss = fetch_rss($url);
    
    if ($rss) {
    
        // print the first item
        if (isset($rss->items[0])) {
            $item = $rss->items[0];
    
            echo "<ul>\n";
            echo "\t<li> <a title=\"$item[description]\" href=\"$item[link]\">".$item['title']."</a></li>\n"; 
            echo "</ul>\n"; 
        }
    }
    else { 
        echo "Error: It's not possible to reach RSS file...\n"; 
    } 
    ?> 
    PHP:
     
    weppos, Jul 5, 2006 IP