Selecting specific custom field when several match path
-
In the RSS feed that I’m using, the images and any type of embedded media are all grouped in a similar way. In order to pull in an image, my code looks like this:
<img src="{{data['child']['http://search.yahoo.com/mrss/']['content']['0']['attribs']['']['url']}}" />The problem, is that some of the items have an embed like a youtube video that is in the same array group, just a change of [‘0’] to [‘1’] or [‘2’] where 0 would be the youtube video and 1 would be the image.
Is there any way that I can poll all [‘#’]’s and only select the one where [‘attribs’][”][‘type’] === image/jpeg?
The data in the RSS feed looks like this:
<media:content url="https://youtu.be"> <media:title type="html"><![CDATA[TITLE]]></media:title> <media:embed url="https%3A%2F%2Fyoutu.be"> <media:param name="type">UTUBEVIDEO</media:param> </media:embed> </media:content> <media:content url="http://www.url.com/image.jpg" type="image/jpeg" height="2106" width="3000"> <media:description type="html"><![CDATA[image caption]]></media:description> </media:content> <media:content url="http://www.url.com/image2.jpg" type="image/jpeg" height="2106" width="3000"> <media:description type="html"><![CDATA[image caption]]></media:description> </media:content>' And for good measure, here is the output from show_data:[http://search.yahoo.com/mrss/] => Array (
[content] => Array (
[0] => Array (
[data] =>
[attribs] => Array (
[] => Array (
[url] => https://youtu.be/
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
[child] => Array (
[http://search.yahoo.com/mrss/] => Array (
[title] => Array (
[0] => Array (
[data] => YouTube Title
[attribs] => Array (
[] => Array (
[type] => html
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
[embed] => Array (
[0] => Array (
[data] =>
[attribs] => Array (
[] => Array (
[url] => https%3A%2F%2Fyoutu.be
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
[child] => Array (
[http://search.yahoo.com/mrss/] => Array (
[param] => Array (
[0] => Array (
[data] => UTUBEVIDEO
[attribs] => Array (
[] => Array (
[name] => type
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
)
)
)
)
)
)
)
[1] => Array (
[data] =>
[attribs] => Array (
[] => Array (
[url] => http://www.url.com/image.jpg
[type] => image/jpeg
[height] => 2106
[width] => 3000
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
[child] => Array (
[http://search.yahoo.com/mrss/] => Array (
[description] => Array (
[0] => Array (
[data] => Image caption
[attribs] => Array (
[] => Array (
[type] => html
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
)
)
)
)
)
‘
The topic ‘Selecting specific custom field when several match path’ is closed to new replies.