Guest User

Untitled

a guest
Jul 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. class SiteMap extends Page {
  4. static $db = array(
  5. );
  6. static $has_one = array(
  7. );
  8. }
  9.  
  10. class SiteMap_Controller extends Page_Controller {
  11.  
  12. /**
  13. * This function will return a unordered list of all pages on the site.
  14. * Watch for the switch between $page and $child in the second line of the foreach().
  15. *
  16. * Note that this will only skip ErrorPage's at the top/root level of the site.
  17. * If you have an ErrorPage class somewhere else in the hierarchy, it will be displayed.
  18. */
  19. function Content() {
  20. $rootLevel = DataObject::get("Page", "ParentID = 0"); // Pages at the root level only
  21. $output = "";
  22. $output = $this->makeList($rootLevel);
  23. return $output;
  24. }
  25.  
  26. private function makeList($pages) {
  27. $output = "";
  28. if(count($pages)) {
  29. $output = '
  30. <ul id="sitemap">';
  31. foreach($pages as $page) {
  32. if(!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title){
  33. $output .= '
  34. <li><a href="'.$page->URLSegment.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
  35. //$childPages = new DataObjectSet();
  36. $whereStatement = "ParentID = ".$page->ID;
  37. $childPages = DataObject::get("Page", $whereStatement);
  38. $output .= $this->makeList($childPages);
  39. $output .= '
  40. </li>';
  41. }
  42. }
  43. $output .= '
  44. </ul>';
  45. }
  46. return $output;
  47. }
  48.  
  49. ?>
Add Comment
Please, Sign In to add comment