Display RSS feed on website

Discussion in 'Scripts' started by jojoman2, Jan 9, 2012.

to remove all ads.
  1. jojoman2

    jojoman2 New Member

    Messages:
    3
    Hi!

    I need help displaying an RSS feed on my website which updates over time, but I only want to include those items which are in a certain category. Is there any way of doing this?
    Any help would be appreciated!
     
  2. conor

    conor New Member

    Messages:
    348
    It depends on a few things. How is the rss generated? if it's a wordpress blog then I'm pretty sure you can filter by category very easily in the url. If not, you could write a PHP program which fetches the rss feed and then filters the results. Which of these cases are you looking for?
     
  3. jojoman2

    jojoman2 New Member

    Messages:
    3
  4. conor

    conor New Member

    Messages:
    348
    Yeah don't think it will be possible to filter by URL with that blog.

    Here's a quick PHP program which will fetch the rss feed, filter it by the $category variable and print the results:

    Code:
    $category = 'Insanity';
    
    $dom = new DOMdocument( );
    
    $success = $dom->load( 'http://circusoflamia.blogg.se/index.rss' );
    if( !$success )
            die( 'failed to load url' );
    
    $elements = $dom->getElementsByTagName( 'item' );
    $items = array( );
    
    foreach( $elements as $element ){
            $item = array( );
    
            if( $element->getElementsByTagName( 'category' )->item( 0 ) == $category ){
                    foreach( $element->childNodes as $node )
                                    $item[ $node->nodeName ] = $node->nodeValue;
                 
                    array_push( $items, $item );
            }
    }
    
    die( print_r( $items ) );
    
    That's just off the top of my head but it should give you an idea on how to do this yourself
     
  5. jojoman2

    jojoman2 New Member

    Messages:
    3
    Thanks a lot for the help! :)
     

Share This Page