SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to display rss images with magpierss

    How can I display the RSS images with magpierss? I have looked around online but cant find any resources about displaying RSS images... does magpierss has this function to display images? If it does not, any other solutions?

    Here is my code, but the $image obviously doesnt work.

    PHP Code:
    <?php
            
    require_once 'magpierss/rss_fetch.inc';
            
            
    $url 'http://globaltolerance.com/?feed=rss2';
            
    $rss fetch_rss($url);
            
    $items array_slice($rss->items$startRow3);

            foreach (
    $items as $item) {
                
    $title $item['title'];
                
    $url   $item['link'];
                
    $image   $item['image'];
                
    $date $item['date_timestamp'];
                
    $desc $item['description'];
                
                if (
    strlen($title) >= 25)
                    {
                    
    $title substr($title,0,24)."...";
                    }
                
                if (
    strlen($desc) >= 25)
                    {
                    
    $desc substr($desc,0,24)."...";
                    }
            
    ?> 
                <!--item-->
                <div class="item">
                    
                    <!--item_left-->
                    <div class="item_left">
                        <a href="#"><?php echo $image;?></a>                
                    </div>
                    <!--item_left-->
                    
                    <!--item_right-->
                    <div class="item_right">
                        <div class="title"><a href="<?php echo $url;?>"><?php echo $title;?></a></div>
                        <div class="desicription"><?php echo $desc;?></div>
                        <div class="date"><?php echo date("l, F jS, Y"$date);?></div>
                    </div>
                    <!--item_right-->
                </div>
                <!--item-->
                
                <?php
                
    }
                
    ?>
    Many thanks,
    Lau

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,398
    Mentioned
    65 Post(s)
    Tagged
    1 Thread(s)
    There are no images in that RSS feed.
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    There are no images in that RSS feed.
    yes i just realised that sorry for using the incorrect example.

    this one should have the image feed,

    http://rss.news.yahoo.com/rss/oped

    then, how do I pull the images from that feed with magpierss?

    thanks.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know anything about magpie, but anyway in your example <image> is a child of <channel>, not <item>. I'm not sure about the magpie syntax, but using simpleXML, you'd get the properties like this:

    PHP Code:
    <?php
    $rss 
    simplexml_load_file('http://rss.news.yahoo.com/rss/oped');
    echo 
    $rss->channel->image->title '<br />';
    echo 
    $rss->channel->image->width '<br />';
    echo 
    $rss->channel->image->height '<br />';
    echo 
    $rss->channel->image->link '<br />';
    echo 
    $rss->channel->image->url '<br />';
    ?>

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JDevereux View Post
    Don't know anything about magpie, but anyway in your example <image> is a child of <channel>, not <item>. I'm not sure about the magpie syntax, but using simpleXML, you'd get the properties like this:

    PHP Code:
    <?php
    $rss 
    simplexml_load_file('http://rss.news.yahoo.com/rss/oped');
    echo 
    $rss->channel->image->title '<br />';
    echo 
    $rss->channel->image->width '<br />';
    echo 
    $rss->channel->image->height '<br />';
    echo 
    $rss->channel->image->link '<br />';
    echo 
    $rss->channel->image->url '<br />';
    ?>
    This is fantastic! thank you. I will look it up about simpleXML - it seems easier to use than magpie!

    Thank you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •