millsy007 Posted December 15, 2008 Share Posted December 15, 2008 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 from the sitemap: <?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>'; } ?> The 'NEXT' link is being assigned the correct value, but the 'PREV' is always linking to the homepage? Any ideas as to why? Link to comment https://forums.phpfreaks.com/topic/137015-previous-record-in-an-array/ Share on other sites More sharing options...
millsy007 Posted December 15, 2008 Author Share Posted December 15, 2008 I think I may be assuming (incorrrectly) that "preceding-sibling" and "following-sibling" work in the same way. The "following-sibling" is getting out the next record. However I read that "preceding-sibling" will select all the sibling elements before the context node. Wheras I would only want the immiedately preceding/previous record, how could I do this? Link to comment https://forums.phpfreaks.com/topic/137015-previous-record-in-an-array/#findComment-715644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.