WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] SimplePie mRSS - Get at media:content URL? (2 posts)

  1. Drew Baker
    Member
    Posted 4 years ago #

    Hi Guys,
    I'm trying to pull in content from a mRSS feed. This is an example of the mRSS item:

    <item>
    	<title><![CDATA[Title Example]]></title>
    	<link>http://example.com/</link>
    	<guid>http://example.com/</guid>
    	<description><![CDATA[movie.mov
    	<br /><img src="http://example.com/image.jpg" />]]></description>
    
    	<pubDate>Fri, 1 Dec 2009 00:42:21 +0000</pubDate>
    	<enclosure url="http://example.com/movie.mov" type="video/quicktime" length="5319922"/>
    	<media:content url="http://example.com/movie.mov" fileSize="5319922" type="video/quicktime" height="270" width="480"/>
    	<media:thumbnail url="http://example.com/big_thumb.jpg" height="480" width="640"/>
    	<media:thumbnail url="http://example.com/small_thumb.jpg" height="135" width="180"/>
    	<media:credit role="client">Client</media:credit>
    	<media:credit role="director">John Doe</media:credit>
    	<media:credit role="agency" >Agency Example</media:credit>
    	<media:credit role="production company">Example Production Company</media:credit>
    	<media:credit role="award winner">Example Award</media:credit>
    </item>

    My question is, how do I get to the media:content url? I'm using this code, but it doesn't work:

    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/feed.php');
    
    // Get a SimplePie feed object from the specified feed source.
    $rss = fetch_feed('http://www.example.com/feed/');
    if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
        // Figure out how many total items there are, but limit it to 5.
        $maxitems = $rss->get_item_quantity(5); 
    
        // Build an array of all the items, starting with element 0 (first element).
        $rss_items = $rss->get_items(0, $maxitems);
    endif;
    ?>
    
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // Loop through each feed item and display each item as a hyperlink.
        foreach ( $rss_items as $item ) : ?>
    
    	<a href="<?php echo $media->content->attributes()->url; ?>">Test</a>
    
    <?php endforeach; ?>

    I get this error:

    Fatal error: Call to a member function attributes() on a non-object...

    I know I'm doing doing this line wrong:
    $media->content->attributes()->url

    What is the correct syntax?

    Thanks!

  2. Drew Baker
    Member
    Posted 4 years ago #

    I figured it out. The confusing thing is that the SimplePie API treats the <media> namespace as <enclosure>.

Topic Closed

This topic has been closed to new replies.

About this Topic