Finding Previous Array Record
Posted: Sun Dec 14, 2008 7:49 pm
I have some code that Creates 'PREVIOUS' and 'NEXT' links for my page depending on the positions within a sitemap. The code works by reading the sitemap into an array and then setting the links to the previous and next records within the sitemap:
The 'NEXT' link is being assigned the correct value, but the 'PREV' is always linking to the homepage?
Any ideas as to why?
Code: Select all
<?php
$domain = $_SERVER['HTTP_HOST'];
// find out the path to the current file:
$path = $_SERVER['SCRIPT_NAME'];
// put it all together:
$currenturl = "http://" . $domain . $path;
include '/home/beachh/public_html/sample.php';
$xml = new SimpleXMLElement($xmlstr);
if(list($next) = $xml->xpath("/urlset/url[loc='$currenturl']/following-sibling::url")){
echo '<li class="next">
<a href="'.(string)$next->loc.'">NEXT</a>
</li>';
}
if(list($prev) = $xml->xpath("/urlset/url[loc='$currenturl']/preceding-sibling::url")){
echo '<li class="previous">
<a href="'.(string)$prev->loc.'">PREV</a></li>';
}
?>
Any ideas as to why?