Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm successfully using fetch_feed() to display an RSS feed inside a dashboard widget. However, I'm unable to load the thumbnail image from the items in the feed. I'm attempting to do it with the get_image_url() method, however, WordPress errors out on that method as an undefined method.

Code is below...

function example_dashboard_widget_function() {
    // Display whatever it is you want to show   
    $rss = fetch_feed( "http://localhost/testsite/wp-content/test.rss" );

     if ( is_wp_error($rss) ) {
          if ( is_admin() || current_user_can('manage_options') ) {
               echo '<p>';
               printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
               echo '</p>';
          }
     return;
}

if ( !$rss->get_item_quantity() ) {
     echo '<p>No RSS items to show!</p>';
     $rss->__destruct();
     unset($rss);
     return;
}

echo "<ul>\n";

if ( !isset($items) )
     $items = 10;

     foreach ( $rss->get_items(0, $items) as $item ) {
          $publisher = '';
          $site_link = '';
          $link = '';
          $content = '';
          $date = '';
          $image = '';

          $image = $item->get_image_url();
//        $image = esc_url( strip_tags( $item->get_thumbnail() ) );

          $link = esc_url( strip_tags( $item->get_link() ) );

          $content = $item->get_content();
          $content = wp_html_excerpt($content, 250) . ' ...';

         echo "<li><img src='$image' /><a href='$link'>$link</a> - $content</li>\n";
}

echo "</ul>\n";
$rss->__destruct();
unset($rss);

} 
share|improve this question

1 Answer 1

up vote 1 down vote accepted

It's a method for completely different thing.

RSS 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to have a “feed logo”, which is a single image to represent the feed. This method returns the notated URL for that image/logo file. get_image_url()

And it complains about undefined because it is method of feed object and you are iterating through feed item objects.

Overall it depends on how your feed works with images. If they are simply included in content - mine them from there (with regex or something simpler if not much text). If images are included in media enclosure try get_enclosures() method.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.