Hey everyone,
I have a CMS that creates an XML file for each article submitted. I use the following code to display a list of the articles with their headers etc but have two changes I would like to make to it.
Firstly, how can I reverse the order they are loaded? Currently it loads the most recently created article first but I would like this the other way around.
Secondly, is there a way I can set it to load from a certain number? So for example, it skips the first 12 then loads the next 5?
Thanks
I have a CMS that creates an XML file for each article submitted. I use the following code to display a list of the articles with their headers etc but have two changes I would like to make to it.
Firstly, how can I reverse the order they are loaded? Currently it loads the most recently created article first but I would like this the other way around.
Secondly, is there a way I can set it to load from a certain number? So for example, it skips the first 12 then loads the next 5?
PHP Code:
<?php
function extractText($array){
if(count($array) <= 1){
for ($i = 0; $i<count($array); $i++){
$node = $array[$i];
$value = $node->get_content();
}
return $value;
}
}
error_reporting(0);
?>
<?php
$dh = opendir('./xml/');
$fileCount = 0;
while ($file = readdir($dh) and $fileCount < 5){
if (eregi("^..?$", $file)) {
continue;
}
$open = "./xml/" . $file;
$xml = domxml_open_file($open);
$root = $xml->root();
$stat_array = $root->get_elements_by_tagname("status");
$status = extractText($stat_array);
$r_array = $root->get_elements_by_tagname("regarding");
$regarding = extractText($r_array);
$ab_array = $root->get_elements_by_tagname("abstract");
$abstract = extractText($ab_array);
$h_array = $root->get_elements_by_tagname("headline");
$headline = extractText($h_array);
if ($status != "live"){
continue;
}
echo "<tr><td><table>";
echo "<tr align=left valign=top><td width='90' align='center'>";
echo "<img src='images/newscat/".$regarding . ".png'></td><td>";
echo "<a class='headline' href=\"showArticle.php?file=".$file . "\">".$headline . "</a><br>";
echo "<span class='bytext'>Posted: " . date ("F d Y H:i", filemtime($open));
echo "</span><br>" . $abstract;
echo "</td></tr></table></td></tr>";
$fileCount++;
}
?>
Comment