Jump to content

Make RSS feed block show media tag url


babyewok

Recommended Posts

OK, so usually I would use simple pie to show a wordpress feed on a website.  I am trying to use the RSS block module but am having trouble with it.  I need to show the featured image which I have added to the feed via a media tag.  My feed looks like this:

 

<title>Post title</title>
		<link>http://website.com/blog/2018/02/post/</link>
		<pubDate>Mon, 15 Feb 2018 08:39:00 +0000</pubDate>
		<dc:creator><![CDATA[Kitty &#38; Dulcie]]></dc:creator>
		<category><![CDATA[Uncategorised]]></category>
		<category><![CDATA[sale]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Blah Blah blah [&#8230;]]]></description>
	<media:content xmlns:media="http://search.yahoo.com/mrss/" medium="image" type="image/jpeg" url="http://website.com/blog/wp-content/uploads/2018/02/image.-2B-25C2-25A3285.00-2Bwww.website.com_.jpeg" width="123" height="185" />	</item>

 

and I would usually then show the feed like this:

<ul>
<?php foreach ($feed->get_items($start,$length) as $item): 	?>
<li> <a href="<?php echo $item->get_permalink(); ?>" class="blog-img"><?php if ($enclosure = $item->get_enclosure())
                            {
                                echo '<img  alt="'.$item->get_title().'" src="' . $enclosure->get_link() . '" />';
							} ?></a>
<h3><a href="<?php echo $item->get_permalink(); ?>"><?php echo substr($item->get_title(), 0, 60);  $str = $item->get_title(); if (strlen($str) > 60) echo '...'; ?></a></h3>
<p><?php echo substr($item->get_description(), 0, strpos($item->get_description(), ' ', 210)). '&hellip;';

 ?> <a href="<?php echo $item->get_permalink(); ?>" class="more-link">Continue Reading</a></p>
<?php endforeach; ?>
			</li></ul>

 

Can anyone enlighten me as to how I can achieve the same with the rss block module?  

Edited by babyewok (see edit history)
Link to comment
Share on other sites

OK, so I have tried all sorts.  The latest is adding this to blockrss.php: 

 

if (isset($xmlValues['media:content']) )
								{
								$xmlValues['imageurl'] = (string)$item->{'media:content'}->attributes()->url;	
								}

after 

$xmlValues = array();
								foreach (self::$xmlFields as $xmlField)
								$xmlValues[$xmlField] = $item->__get($xmlField);
								$xmlValues['enclosure'] = $item->getEnclosure();
								

								// First image
								if (isset($xmlValues['content']) && $xmlValues['content'])
								{
									preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/', $xmlValues['content'], $image);
									if (array_key_exists(1, $image) && $image[1])
									{
										if ($image[1][0] == '/')
											$image[1] = 'http:'.$image[1];
										// Try if distant image exist : timeout 0.3s
										$context = stream_context_create(array('http' => array('timeout' => 0.3)));
										if (file_get_contents($image[1], false, $context, -1, 1) !== false)
											$xmlValues['image'] = $image[1];
									}
								}

 

and then trying to grab the url in the template with... {$rss_link.imageurl}

Doesn't work.  I am sure I have got the logic wrong somewhere - please help!

Link to comment
Share on other sites

  • 11 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...