Make RSS Displayer to show images from posts

Permalink 1 user found helpful
Hi

I have a site, build with Concrete5 and a separate blog using WP.

I am using the RSS Displayer to show descriptions from the blog into my home page but I would also like to show an image from the post.

I am amateur when it comes to web design so my first attempt was to force the first image in front of the description in the wp rss feed. That was easy thought a wp plugin.

Is there a way of having the RSS Displayer showing images from that feed.

My php knowledge is limited so i am looking for something easy to implement.

Thanks

 
jordanlev replied on at Permalink Reply
jordanlev
I don't see why the RSS Displayer would hide images -- it's more likely that something on the wordpress side is not putting the images in the feed in the first place. You can test this out by viewing the wordpress feed from a feed reader program (like Google Reader or NetNewsWire or whatever), and seeing if the images come up there. If they don't, then you'd have better luck asking the question "how do I get my images to appear in my RSS feed" on a wordpress forum.

Good luck!
WCHammer replied on at Permalink Reply
I have the same issue,

My images are coming up, but as the file name rather than displaying a picture
I've tested the rss feed itself and it displays the image fine.

It's also worth noting that the RSS displayer seems to take FOREVER to update, despite re-adding the block etc etc
oaknshield replied on at Permalink Reply
oaknshield
Hi

Did you ever get your RSS feed to show images ?
I am having the same problem.

its driving me nuts
akaraolis replied on at Permalink Reply
Hi
No i couldn't make it work. Instead i used rss2html. There are a few other options as well. Too bad for concrete5 though the support could be better.
oaknshield replied on at Permalink Reply
oaknshield
OK - i got a solution - - kinda (reaal stress-geeez)
...images now loading in my RSS feed in C5 from my Wordpress blog

i copied the folder concrete/blocks/rss_diplayer and put it in blocks - so now have blocks/rss_displayer to play with

i edited the view.php
replaced
<?php 
if( $rssObj->showSummary ){
echo $textHelper->shortText( strip_tags($item->get_description()) );
}?>


with
<?php
$htmlrss = $item->get_content();
 if( $rssObj->showSummary ){
echo $htmlrss;
}
?>


igot this from a previous post
http://www.concrete5.org/community/forums/customizing_c5/rss-block/...
however i changed get_description to get_content

IMAGES WORKING......
BUT. problem is - - it is not truncating - maybe someone with php knowledge can help with this.

sooooo. i improvised by adding a scollbar for each RSS feed.
i edited the view.css and addded height& overflow to the foll class
rssSummaryList .rssItem
{height: 400px;
overflow: auto;
margin-bottom:16px }


so now each RSS article from Wordpress shows images/text with a scrollbar at side to read more if its less than 400px it will show no scroll bar - - if a user wants he/she can just click on title to read properly

i would've liked it to be truncated properly but for now its working - it doesnt look too bad ......

hope this could help you
i buss my nuts with this
jordanlev replied on at Permalink Reply
jordanlev
This is a tricky problem. The images are not actually embedded in the text of the feed, but rather some text that points to the image (an html <img> tag) -- what this means is that you can either show the images or you can truncate the text, but you can't do both. Because the truncation might cut off the image tag halfway in the middle, and you'd wind up with a bunch of gibberish that made no sense.
There is probably some complicated way to do both truncation and images, but nothing like that exists in the system already so unless you are an experienced programmer and it's worth the time for you to figure out, I'd probably not bother.
jkernick replied on at Permalink Reply
jkernick
Has anyone ever found a solution to this problem? I added this bit of code:

<? function get_first_image_url($html)
                  {
                  if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
                  return $matches[1];
                  }
                     else echo '';
                  }
                  echo '<img src="' .get_first_image_url($item->get_content()). '" style="float:left; margin-right:5px;" />';
                  ?>


but the problem now is if I have more than one feed using the RSS displayer block, I get an error

Fatal error: Cannot redeclare get_first_image_url() (previously declared in /var/www/blocks/rss_displayer/view.php:32) in /var/www/blocks/rss_displayer/view.php on line 32


I have multiple feeds that each need to display a thumbnail image. Will this ever be an option in the RSS block???
jordanlev replied on at Permalink Reply
jordanlev
Not sure about your specific code, but in general if you're having a problem with a function being re-declared in php, you can do this:

<?php
if (!function_exists('get_first_image_url')) {
  function get_first_image_url($html) {
    //...function code here....
  }
}
?>


Now that block or whatever can be added to the page several times and only the first one will declare the function. Just make sure there's nothing in that function that makes any assumptions about which block it's being used for -- it must be a very general "utility" function that only operates on the parameters passed to it -- $html in this case.
jkernick replied on at Permalink Reply
jkernick
Thanks, but I actually want both blocks to declare the function. In other words, I'm using RSS Displayer for two different feeds, each one in its own block. I want the first image from each feed to show up. It works for the first feed, but dies for the second. Any suggestions on how I can get the function be declared two different times?
jordanlev replied on at Permalink Reply
jordanlev
Don't declare the function 2 times. Instead, make the block ID or some other identifying variable an argument to the one function. Treat the function as more of a general utility that works for any block.

-Jordan
jkernick replied on at Permalink Reply
jkernick
Could you show me a code example? I’m a n00b to PHP and I learn best by example!
jordanlev replied on at Permalink Reply
jordanlev
Looking at the function you posted above, I don't see any reason why it won't work the way you're describing. If you're getting some other error, please explain it in more detail. Also if it's not working, it would be helpful if you posted more code (for example, if this is a custom template for the page_list block, just provide the whole view.php file).
jkernick replied on at Permalink Reply
jkernick
thanks for your help, here is my view.php code for RSS Displayer:

<?php  defined('C5_EXECUTE') or die("Access Denied."); 
?>
<div id="rssSummaryList<?php echo intval($bID)?>" class="rssSummaryList">
<?php  if( strlen($title)>0 ){ ?>
   <div class="rssSummaryListTitle" style="margin-bottom:8px"><?php echo $title?></div>
<?php  } ?>
<?php  
$rssObj=$controller;
$textHelper = Loader::helper("text"); 
if (!$dateFormat) {
   $dateFormat = t('F jS');
}
if( strlen($errorMsg)>0 ){
   echo $errorMsg;
}else{


The image for the first feed appears, but the image for the second feed does not. I know you said I could pass an argument to show both images, how would I code that?
jordanlev replied on at Permalink Reply
jordanlev
What I meant is you already *are* doing that. But I think the reason your code isn't working is because this line:
echo '<img src="' .get_first_image_url($item->get_content()). '" style="float:left; margin-right:5px;" />';

...is inside the "if (!function_defined)..." curly braces, so it's not getting called after the first time. (When programming, it's generally a good habit to keep your indentation nice and clean so that these kinds of errors -- which are very common for everyone -- are easy to spot).

Move that line so it's below the closing brace "}" below it and it should work.
jkernick replied on at Permalink Reply
jkernick
it works! THANK YOU SO MUCH!!!! you have been extremely helpful!
WCHammer replied on at Permalink Reply
Holy moley

Can you post the full code for view.php?
This is all a bit confusing...
jordanlev replied on at Permalink Reply
jordanlev
She already did -- see the response above with all the code in it (http://www.concrete5.org/community/forums/customizing_c5/make-rss-d... ). The only thing you'll need to change is moving the line that starts with "echo '<img src=..." down one line so it's below the closing curly brace.
FatTony1952 replied on at Permalink Reply
FatTony1952
I have found only one issue with this solution.

In mobile Safari, I get the question mark icon that an image is missing. In IE9 the 'missing' image gets completely repeated below the current image leaving a large blank spot.

I will try to get a screen shot of the IE issue and post. The mobile Safari issue isn't as big of a deal.
FatTony1952 replied on at Permalink Reply
FatTony1952
I have the issue partially tracked down. I have a default image to show if a particular rss item doesn't have an image.

Here is my code:

<?php 
            if (!function_exists('get_first_image_url')) 
            {
            function get_first_image_url($html) 
                {
                      {
                      if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) 
                        {
                        return $matches[1];
                        }
                         else echo '<img src="<?php echo DIR_REL ?>/images/placeholder.jpg" />';
                      }
                }
            }
                echo '<img src="' .get_first_image_url($item->get_content()). '" />';


What is happening is if there isn't an image, it displays the placeholder image, but also tries to display the missing image. In IE, this makes a large blank gap below the placeholder image.
FatTony1952 replied on at Permalink Reply
FatTony1952
Okay, so I figured it out. In order to display a default image if a particular feed item doesn't have an image, this line:

else echo '<img src="<?php echo DIR_REL ?>/images/placeholder.jpg" />';


should read:

else return '<?php echo DIR_REL ?>/images/placeholder.jpg';