I have an XML blog feed that I am displaying on a Wordpress. Here is a simple representation of the XML nodes:
<item>
<title>
Some title
</title>
<description>
Some description
</description>
<category>
category 1
</category>
<category>
category 2
</category>
<category>
category 3
</category>
</item>
So you'll notice above the category node is displayed 3 times but always has the same name. So when I'm using the below PHP to display the XML nodes in a loop I can only get one of the category nodes as the rest aren't unique.
Does anyone know how I can display all of those category nodes please???
<?php
$rss = new DOMDocument();
$rss->load('http://blog.com/rss.xml');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'category' => $node->getElementsByTagName('category')->item(0)->nodeValue,
);
array_push($feed, $item);
}
?>
<?php
$limit = 3;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$description = $feed[$x]['desc'];
$category = $feed[$x]['category'];
echo $title;
echo $desc;
echo $category;
}
?>