5102 Posts in 1520 Topics by 1116 members
| Go to End | ||
| Author | Topic: | 4488 Views |
-
Re: Page Controls: Next/Previous Page Link?

4 February 2011 at 12:28am
cbolt's solution worked well for me. I made two minor edits...
PreviousPage function would fail if Children return a dataobjectset with no children. So updated the function to use Count():
function PreviousPage() {
$where = "ParentID = {$this->ParentID} AND Sort < {$this->Sort}";
$pages = DataObject::get("SiteTree", $where, "Sort DESC", "", 1);
if($pages) {
foreach($pages as $page) {
// if page has a child go to the last child page
$children = $page->AllChildren();
if ($children->Count()) {
foreach ($children as $child) {
continue;
}
return $child;
}
return $page;
}
}I also updated both functions Where clauses to only return pages shown in the menu. ie:
$where = "ParentID = $parent AND `SiteTree`.ID != 4 AND Sort > $sort AND ShowInMenus = 1";
| 4488 Views | ||
| Go to Top |

