2013-03-02 11 views
-3

這將輸出飼料的所有圖像,但我只想顯示第一個,我必須在標記而不是foreach中輸入什麼內容?一次,而不是在RSS飼料的foreach?

 <?php foreach ($feed->get_items() as $item): ?> 



     <?php $media_group = $item->get_item_tags('', 'enclosure'); 
     $file = $media_group[0]['attribs']['']['url']; 
     ?> 



     <?php echo ' 

    <img width="200" src="' .$file. '"/>'; ?> 

     <?php endforeach; ?> 

回答

0
<?php $items = $feed->get_items(); $item = $items [0]; ?> 
<?php $media_group = $item->get_item_tags('', 'enclosure'); 
     $file = $media_group[0]['attribs']['']['url']; 
?> 
<?php echo '<img width="200" src="' .$file. '"/>'; ?> 
+0

'$項目=重置($項目)'可能會用不同的數組鍵更好地工作。 – DCoder 2013-03-02 08:37:50

+0

非常感謝! – user1826828 2013-03-02 08:38:35