Viewing 13 replies - 1 through 13 (of 13 total)
  • I am trying to sort this one out myself. I have one feed that I know has thumbnails but it shows no images.

    https://www.amazon.com/gp/rss/new-releases/books/6/ref=zg_bsnr_6_rsslink

    Then I have another that also has images and it shows some of them but not all.

    The standard WP RSS widget behaves the same way.

    The RSS Multi-Importer RSS feed imports with all the pictures but does not provide the other features I prefer with this plugin I am testing.

    Unclear if I will stick with this one or not. I have created a few different styles so it would be a shame to cross this one off.

    At the moment, as far as I can tell, thumbnail images will only display if you are showing the RSS description. Make sure you have Show Description ticked in your options.

    If you want to show Thumbnails without the description, a temporary workaround would be to go into the Plugin Editor and edit the file super-rss-reader/super-rss-reader.php.

    Find the following code:

    $thumb = '';
    if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
      $thumburl = $enclosure->get_thumbnail();
      if(!empty($thumburl))
        $thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }

    And change it so it reads:

    $thumb = '';
    if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
      $thumburl = $enclosure->get_thumbnail();
      if(!empty($thumburl))
        $thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }
    if (!$show_desc && $show_thumb) $title = $thumb . $title;

    This will display the thumbnail to the left of the title.

    Hey Jarada, this totally doesn’t work for me.

    Here’s my feed: https://9to5.cc/keith/feed/ which has the code (for example):
    <enclosure url=”https://9to5.cc/keith/files/2013/08/dirties1-150×150-1376497869.jpg&#8221; length=”10515″ type=”image/jpg”/>

    But no thumb is showing.

    And here is how the plugin appears: https://9to5.cc/test/

    I’m having the same issue.

    Guess I will have to find a different widget?

    The images don’t for me either. I’m using Interspire Shopping Cart feeds. I don’t see how this plugin is grabbing the image. If it grabs it from the description, it would be grabbing the wrong image anyway like the multi rss importer did. This is the enclosure for the Interspire thumbnail image in the rss feed: <isc:thumb>

    Some other dirty temporary workarounds.
    In my case, the image is embedded in the rss description tag like in the example:
    <description><![CDATA[ <img src="https://www.my-site-rss.com/post/13/12087/12087/small.jpg" alt="alt" /> other rss description text ... ]]> </description>
    So I can extract the src attribute of my image tag using dwo different php function.
    The first, the bad one, with some bad and slow regex code:

    preg_match_all('/<img src=\"(.*?)\".*\/>/', $item->get_description(), $images);
    $thumb = '';
    if ($show_thumb == 1 && !empty($images[1][0])){
       $thumb = '<img src="' . $images[1][0] . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }

    The second one, if your server come with DOM functions, you can fastly extract your URL:

    $doc = new DOMDocument();
    $doc->loadHTML("<p>".$item->get_description()."</p>");
    $tags = $doc->getElementsByTagName('img');
    foreach ($tags as $tag) {
       $src[] = $tag->getAttribute('src');
    }
    if ($show_thumb == 1 && !empty($src)){
       $thumb = '<img src="' . $src[0] . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }

    A last elegant solution consists in replacing this code

    // Get thumbnail if present @since v2.2
    $thumb = '';
    if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
    	$thumburl = $enclosure->get_thumbnail();
    	if(!empty($thumburl))
    		$thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }

    with this one that will search the image tag in the description too:

    $thumb = '';
    if($show_thumb == 1) {
    	$enclosure = $item->get_enclosure();
    	// if we have a proper XML tag for our rss-feed image
    		if(!empty($enclosure->thumbnails)) {
    			$thumburl = $enclosure->get_thumbnail();
    			// else we will search a <img> tag in our description
    		} elseif(stripos($item->get_description(), 'formula') !== false) {
    
    		// is DOM module present in our PHP installation?
    		if (class_exists('DOMDocument')) {
    			$dom = new DOMDocument();
    			$dom->loadHTML("<div>".$item->get_description()."</div>");
    			$images = $dom->getElementsByTagName('img');
    			foreach($images as $image) {
    				$src[] = $image->getAttribute('src');
    			}
    			$thumburl = $src[0];
    
    		// if not, we will use a slower preg_match regex...
    		} else {
    			$images = Array();
    			preg_match_all('/ src=\"(.*?)\".*\/>/', $item->get_description(), $images);
    			$thumburl = $images[1][0];
    		}
    	}
    	// if, at last, we have filled our $thumburl
    	if(!empty($thumburl)) {
    		$thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    	}
    }

    So, the last working version is:

    $thumb = '';
    if($show_thumb == 1) {
    	$enclosure = $item->get_enclosure();
    	// if we have a proper XML tag for our rss-feed image
    	if(!empty($enclosure->thumbnails)) {
    		$thumburl = $enclosure->get_thumbnail();
    
    	// else we will search a <img> tag in our description
    	} else
    	if(stripos($item->get_description(), '<img') !== false) {
    
    		// is DOM module present in our PHP installation?
    		if (class_exists('DOMDocument')) {
    			$dom = new DOMDocument();
    			$dom->loadHTML("<div>".$item->get_description()."</div>");
    			$images = $dom->getElementsByTagName('img');
    			$src = Array();
    			foreach($images as $image) {
    				$src[] = $image->getAttribute('src');
    			}
    			$thumburl = $src[0];
    
    		// if not, we will use a slower preg_match regex...
    		} else {
    			$images = Array();
    			preg_match_all('/ src=\"(.*?)\".*\/>/', $item->get_description(), $images);
    			$thumburl = $images[1][0];
    		}
    	}
    // if, at last, we have filled our $thumburl
    	if(!empty($thumburl)) {
    		$thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    	}
    }

    Salam,

    i run into this problem just now and i noticed that the above code is missing another part where you need to add $thumb in output.
    so for me this is the working version.
    1. make sure your feed has enclosure check at
    yourblog.com/category/feed
    1.i if your feed doesn’t have enclosure please add this code to your theme’s function.php file

    add_action('rss2_item', function(){
      global $post;
    
      $output = '';
      $thumbnail_ID = get_post_thumbnail_id( $post->ID );
      $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'thumbnail');
      $mime = get_post_mime_type($thumbnail_ID);
      $output = '<enclosure url="'.$thumbnail[0].'" type="'.$mime.'"/>';
      echo $output;
    });

    2. go into the Plugin Editor and edit the file super-rss-reader/super-rss-reader.php replace this code for me its on 325th line.

    // Get thumbnail if present @since v2.2
    $thumb = '';
    if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
    	$thumburl = $enclosure->get_thumbnail();
    	if(!empty($thumburl))
    		$thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }

    with this

    // Get thumbnail if present @since v2.2
    				if($show_thumb == 1) {
     				$enclosure = $item->get_enclosure();
    				// if we have a proper XML tag for our rss-feed image
    				if($enclosure->get_link()) {
    					$thumburl = $enclosure->get_link();
    				// else we will search a <img> tag in our description
    				} else{
    					$thumburl = "url to temp image.png";//$item->get_thumbnail();
    				}
    				// if, at last, we have filled our $thumburl
    				if(!empty($thumburl)) {
    					$thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" style="float: right !important;margin: 0 0 0 10px!important; border: 1px solid;30px !important"/>';
    				}
    				}
     				// end if show tabs

    in above code there “url to temp image.png don’t forget to replace it with your own temp image in case the thumbnail is not available.
    and also you can change the style style=”float: right !important;margin: 0 0 0 10px!important; border: 1px solid;30px !important” to whatever you like i wanted the image to show on the right side of title.

    3. on the same file find // Display the feed items
    original code

    echo '<div class="srr-title"><a title="Posted on ' . $date . '">' . $title . '</a></div>';

    i wanted the image to show on the right side of my feed title.
    so i changed to

    echo '<div class="srr-title"><a title="Posted on ' . $date . '">'.$thumb. $title . '</a></div>';

    see above i added $thumb before title

    that’s all hope it helps some one.
    Best, From Afghanistan.

    A bit of workaround this:

    On my case, i have Super RSS Reader reading feed from another wordpress installs. They send a link to image on enclosure item thanks to another plugin called “Insert RSS Thumbnails”. The problem are, who they doesn’t send “Thumbnail” tag, instead send directly the “link” tag on Enclosure.

    The info received on the Super RSS Reader (Thanks to var_dump($enclosure), but I’ve deleted the NULL values except one for better legibility):

    NULL
    object(SimplePie_Enclosure)#5644 (27) {
      ["length"]=>
      float(2854)
      ["link"]=>
      string(58) "https://semosfrikis.blogs.enelia.com/files/2013/12/logo.png"
      ["restrictions"]=>
      array(1) {
        [0]=>
        object(SimplePie_Restriction)#5647 (3) {
          ["relationship"]=>
          string(5) "allow"
          ["type"]=>
          NULL
          ["value"]=>
          string(7) "default"
        }
      }
      ["thumbnails"]=>
      NULL
      ["type"]=>
      string(10) "image/jpeg"
    }

    A little solution, but very effective:

    Find:

    $thumb = '';
    if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
      $thumburl = $enclosure->get_thumbnail();
      if(!empty($thumburl))
        $thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }

    Change with:

    // Get thumbnail if present @since v2.2
    $thumb = '';
    
    if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
    	$thumburl = $enclosure->get_thumbnail();
    	if(empty($thumburl)) $thumburl = $enclosure->get_link();
    	if(!empty($thumburl))
    	$thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
    }

    The only change are this line:
    if(empty($thumburl)) $thumburl = $enclosure->get_link();

    I think, some of this changes can be a good change for the plugin mainstream. Not neccesary my change.

    @er_maqui

    i haven’t tested your solution but for one part it, you still need to echo $thumb on the output.

    @genuskbl

    In my case, I’m showing description. Because this, this solution it’s working.

    But, also, this can be a good idea. The plugin have a “show thumb” option, the mantainer can change the code to show thumb always they’re selected and available, not only when show description (long text).

    @er_maqui
    Indeed, but my solution was for only title and thumbnails. so for those who likes to show only title and thumbnail it they must do that because the plugin will not print the thumb otherwise.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to display thumbnail ? doesnt work at my wp site v.3.5.1’ is closed to new replies.