PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 3rd, 2012, 03:53 PM
stevenatherton4 stevenatherton4 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 87 stevenatherton4 New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 1 Day 18 h 45 m 18 sec
Reputation Power: 0
PHP-General - Displaying thumbnails from RSS feed

Hello

I'm trying to display a RSS feed and display the media:thumbnail image with it.

I've got the feed working fine, but I'm struggling with displaying the thumbnails correctly. I'm using MTV news feed: http://www.mtv.co.uk/rss/news

The code I'm using is:

PHP Code:
 $url "http://www.mtv.co.uk/rss/news";
$rss simplexml_load_file($url);

$data $rss->xpath ('channel/item/media:thumbnail');


if(
$rss)
{
echo 
'<h1>'.$rss->channel->title.'</h1>';
echo 
'<li>'.$rss->channel->pubDate.'</li>';
$items $rss->channel->item;
foreach(
$items as $item)
{
$title $item->title;
$link $item->link;
$img $item->thumbnail;
$published_on $item->pubDate;
$description $item->description;

echo 
'<h3><a href="'.$link.'">'.$title.'</a></h3>';
foreach (
$data as $item) {
    
    echo 
'<img src="'.$item['url'].'" />';
    
}
echo 
'<span>('.$published_on.')</span>';
echo 
'<p>'.$description.'</p>';

}




If you look on http://www.teenchill.co.uk you'll see the problem. The feed displays correctly, but all 10 thumbnails are displayed rather than one for each news story.

Can anyone point me in the right direction?

Many thanks
__________________
hair extensions

Reply With Quote
  #2  
Old June 3rd, 2012, 04:59 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,713 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 1 m 10 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
PHP Code:
 $data $rss->xpath ('channel/item/media:thumbnail'); 

That will get all the thumbnails. To get just the one from the current <item> change
PHP Code:
 $img $item->children("media"true)->thumbnail

Reply With Quote
  #3  
Old June 3rd, 2012, 06:22 PM
stevenatherton4 stevenatherton4 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 87 stevenatherton4 New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 1 Day 18 h 45 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
PHP Code:
 $data $rss->xpath ('channel/item/media:thumbnail'); 

That will get all the thumbnails. To get just the one from the current <item> change
PHP Code:
 $img $item->children("media"true)->thumbnail


Hello, thanks for the reply. I'm a little confused. Do I need to replace

PHP Code:
 $data $rss->xpath ('channel/item/media:thumbnail'); 


with
PHP Code:
 $img $item->children("media"true)->thumbnail


?

I've been messing around with this for a while now and only either manage to display all the images or none.

Reply With Quote
  #4  
Old June 3rd, 2012, 06:37 PM
stevenatherton4 stevenatherton4 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 87 stevenatherton4 New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 1 Day 18 h 45 m 18 sec
Reputation Power: 0
I think I have it figured out. I used:

PHP Code:
 $thumbAttr $item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes(); 


Instead of

PHP Code:
 $img $item->children("media"true)->thumbnail


then echoed

PHP Code:
 $thumbAttr['url'


and that seems to have done the trick.

Thanks for your help.

Reply With Quote
  #5  
Old January 19th, 2013, 09:50 AM
Phosphene Phosphene is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 Phosphene User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 28 sec
Reputation Power: 0
Hello,

I am trying to do something similar, could you please post your final code here?

Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Displaying thumbnails from RSS feed

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap