Wordpress 提要 RSS XML - PHP 媒体
Wordpress Feeds RSS XML - PHP media
我有这段代码,但我不知道如何获得 media
有人能帮帮我吗?
我需要在我的网站上显示 post 的图像
低于我的 PHP 和 XML 的 Wordpress Feed
PHP
$html = "";
$url = "https://intercambioemgalway.com.br/feed/";
$xml = simplexml_load_file( $url, 'SimpleXMLElement', LIBXML_NOCDATA );
for ($i = 0; $i < 5; $i++){
$img = $xml->channel->item->media;
$html .= "$img";
}
echo $html;
XML
<item>
<title>Qual escola vou estudar?</title>
<link>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/</link>
<comments>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/#respond</comments>
<pubDate>Mon, 11 Sep 2017 17:36:59 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<category><![CDATA[Meu intercâmbio]]></category>
<guid isPermaLink="false">https://intercambioemgalway.com.br/?p=179</guid>
<description><![CDATA[<p>Hoje vou contar um pouquinho da escola que vou estudar em Galway, a Atlantic Language.</p>]]></description>
<wfw:commentRss>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
<media:content url="https://intercambioemgalway.com.br/wp-content/uploads/2017/09/Untitled-1.jpg" type="image/jpeg" medium="image" width="900" height="600">
<media:title type="plain">
<![CDATA[atlantic-language-galway]]>
</media:title>
<media:thumbnail url="https://intercambioemgalway.com.br/wp-content/uploads/2017/09/Untitled-1-150x150.jpg" width="150" height="150" />
<media:description type="plain">
<![CDATA[]]>
</media:description>
<media:copyright>
admin
</media:copyright>
</media:content>
每个 $item
都是 SimpleXMLElement 类型。
现在您可以使用命名空间 http://search.yahoo.com/mrss/
循环子项,然后您可以访问 attributes.
例如:
foreach($xml->channel->item as $item) {
foreach($item->children("http://search.yahoo.com/mrss/") as $media) {
$img = (string)$media->attributes()->url;
}
}
我有这段代码,但我不知道如何获得 media
有人能帮帮我吗?
我需要在我的网站上显示 post 的图像
低于我的 PHP 和 XML 的 Wordpress Feed
PHP
$html = "";
$url = "https://intercambioemgalway.com.br/feed/";
$xml = simplexml_load_file( $url, 'SimpleXMLElement', LIBXML_NOCDATA );
for ($i = 0; $i < 5; $i++){
$img = $xml->channel->item->media;
$html .= "$img";
}
echo $html;
XML
<item>
<title>Qual escola vou estudar?</title>
<link>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/</link>
<comments>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/#respond</comments>
<pubDate>Mon, 11 Sep 2017 17:36:59 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<category><![CDATA[Meu intercâmbio]]></category>
<guid isPermaLink="false">https://intercambioemgalway.com.br/?p=179</guid>
<description><![CDATA[<p>Hoje vou contar um pouquinho da escola que vou estudar em Galway, a Atlantic Language.</p>]]></description>
<wfw:commentRss>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
<media:content url="https://intercambioemgalway.com.br/wp-content/uploads/2017/09/Untitled-1.jpg" type="image/jpeg" medium="image" width="900" height="600">
<media:title type="plain">
<![CDATA[atlantic-language-galway]]>
</media:title>
<media:thumbnail url="https://intercambioemgalway.com.br/wp-content/uploads/2017/09/Untitled-1-150x150.jpg" width="150" height="150" />
<media:description type="plain">
<![CDATA[]]>
</media:description>
<media:copyright>
admin
</media:copyright>
</media:content>
每个 $item
都是 SimpleXMLElement 类型。
现在您可以使用命名空间 http://search.yahoo.com/mrss/
循环子项,然后您可以访问 attributes.
例如:
foreach($xml->channel->item as $item) {
foreach($item->children("http://search.yahoo.com/mrss/") as $media) {
$img = (string)$media->attributes()->url;
}
}