• Resolved bbhank

    (@bbhank)


    Using WordPress rss code.
    Problem is how to show images from feeds when available.
    Code below works but could find nothing that succinctly shows how to display images from feeds, not featured images from posts on own site.
    Need code that works for this.

    <?php if(function_exists('fetch_feed')) {
    
    	include_once(ABSPATH . WPINC . '/feed.php'); // the file to rss feed generator
    	$feed = fetch_feed('https://anyfeed.com'); // specify the rss feed
    
    	$limit = $feed->get_item_quantity(6); // specify number of items
    	$items = $feed->get_items(0, $limit); // create an array of items
    
    }
    if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>';
    else foreach ($items as $item) : ?>
    <FONT FACE='Georgia,serif' SIZE="2"  COLOR="#000000"><b>
    <a href="<?php echo $item->get_permalink(); ?>" alt="<?php echo $item->get_title(); ?>"><?php echo $item->get_title(); ?></a></b></FONT>
    <FONT COLOR="#000000"><i><?php echo $item->get_date('j F Y @ g:i a'); ?></i>
    <p><?php echo substr($item->get_description(), 0, 200); ?> ...</p></FONT>
    
    <?php endforeach; ?>
Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator bcworkz

    (@bcworkz)

    Please see Customizing Feeds. You make your own template (start with the default) that includes images. It’s possible some feed readers will refuse to fetch the imagery. If you enter the feed URL in your browser and the images display, you’ve done what you can on your end. Changing feed readers is all that can be done on the other end.

    Thread Starter bbhank

    (@bbhank)

    Yes.
    Thank you.
    Been to this page. It does not show how to display images from external feeds if and/or when they exist.
    Please review code and question above.

    Using the code above, how to display images from external rss feeds, is the question.

    Thread Starter bbhank

    (@bbhank)

    I guess I’m going in the opposite direction. Trying to display images contained in feeds coming in, not from my site going out.
    Hope this helps.

    Moderator bcworkz

    (@bcworkz)

    Yeah, I got it now. You didn’t mention external in your OP and since you said your code worked, I didn’t look at it very closely.

    The item/post description will generally not contain images unless the feed was customized as mentioned in that Codex page I linked previously. (more on this in a bit) In particular, the default feed will not contain featured images at all unless they are also part of post content. (theme dependent) To display post content, images and all, output $item->get_content().

    If you want to only display post images from content, without the text, search through the returned content string for tags. Use preg_search() to be able to extract all the full tags into $matches, then step through the array and output each match/img tag.

    There’s an alternate method of customizing your feed to contain featured images. You can use the “the_excerpt_rss” filter to inject featured images into the excerpt. Something like this:

    function featured_to_RSS( $excerpt ) {
       global $post;
       if ( has_post_thumbnail( $post->ID ) ){
          $excerpt = '<div>' . get_the_post_thumbnail( $post->ID, 'medium') . '</div>' . $excerpt;
       }
       return $excerpt;
    }
    add_filter('the_excerpt_rss', 'featured_to_RSS');

    With this your current code will include featured images in the output, if they exist. For completeness, you may want to also use add_filter('the_content_feed', 'featured_to_RSS'); to include the featured image in post content. Your code ignores it, but if it’s in the excerpt, one would expect it to also be in content.

    Thread Starter bbhank

    (@bbhank)

    I’m not customizing my own feed. I’m wanting to display the images in feeds already made, that are not from, or on, my site. Feeds like news from major outlets, or imagery, from sites like NASA. Images need to be sized freely. There are plugins that do this but not as cleanly and controllable as this script.

    Thread Starter bbhank

    (@bbhank)

    Through some searching found the images are contained in the Description field. Many feeds don’t have images. Depends on how many characters are shown in that field as to whether images will show at all, as most are not at the beginning of the field, but inline with text in the field.

    Moderator bcworkz

    (@bcworkz)

    Like I said, images inline with the post can be extracted from the content. You are correct, the description/excerpt may or may not include images, depending on placement. The content will of course have all inline images. You will still not get featured images. They do not exist in the default feeds. The only way to get featured images is by customizing your feed, unless your theme has already done so for you.

    Thread Starter bbhank

    (@bbhank)

    I was using Feedsweep to do this. They have “disappeared”. They’re just gone. No warning. No info. Did a lot of searching. Their feeds contained lots of images. Looking for that kind of aggregator/aggregation.

    Thread Starter bbhank

    (@bbhank)

    Having to start from scratch to find something that is a fit for my sites. So far the code route has been best and most easily customizable.
    Looking for the kind of customization that was offered in Feedsweep. There seems to be no current information (???) about this service even though they were doing this for years.
    Any Ideas, suggestions here?

    Moderator bcworkz

    (@bcworkz)

    suddenly unsure of context, reads backscroll
    Oh, right. But I don’t know why I keep saying customize your feed. They’d have to customize their feed, assuming another WP site. You can only work with what is served.

    As a coder, when I want something done a certain way, I code it. I’ve no experience with things like feedsweep. If there are images in a feed, you can get them, but not in the description/excerpt. SimplePie_Item, the feed item objects you get with fetch_feed(), makes it easy to access any part of a feed item. You can achieve any customization you want. You need to figure out where in the feed item those images are. Fetch the feed yourself in your browser, then view the page source. It’s simply an XML file, it’s structure is readily apparent. Find out how the images are placed in the structure. A combination of object methods and PHP string manipulation will let you get what you want one way or another, if it’s there at all.

    You can spend time trying different feedsweep-like platforms and learning how to customize it, if it’s even possible, or code up exactly what you want from the start.

    Thread Starter bbhank

    (@bbhank)

    Not everybody is a big coder. Been there. Tried that.
    Looking for another Feedsweep like platform.
    Know of any? Any suggestions on workable plugins? Going through the “Best Of”s and Top X#s right now.
    I’m looking at those routes as well.
    Anybody else know of any other workable solutions and/or info on how to customize the code above?

    And, anyone know anything about what happened to Feedsweep? It was around for years then without warning around Sept 22 it was like it never existed at all. Only old links from the search engines exist now. It worked well as a short coded item. The feeds were set up on their site where their code was generated. All formatting was done there. The code then could be copied and pasted into the WordPress shortcode and/or widget maker.

    Thread Starter bbhank

    (@bbhank)

    SimplePie.
    Definitely not simple but might be the pie needed.

    Thank you.

    Moderator bcworkz

    (@bcworkz)

    You’re welcome, sorry I couldn’t be of more help. BTW, I’m not a “big coder”, or at least don’t consider myself to be. I’m a hobbyist coder with some free time. It’s nowhere near my profession, I’m entirely self taught, there are some glaring holes in what I know, things any professional should know. I can cobble together all sorts of clever customizations, but as soon as any significant project shows up, I go running for the best plugin like anyone else would.

    That is weird about feedshare, completely disappeared. I’ve no idea why. The take away is if the images are in the feed somewhere, you can get at them, even as a “little coder” ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Display Images in rss Feeds’ is closed to new replies.