Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

adding next and previous page


Reply

7 Posts   2830 Views

Avatar
Nicolaas

30 May 2007 at 9:26pm Forum Moderator, 213 Posts

Hi

I would like to add a next and previous page.... I am a completely newbie, but I am not giving up. I am kind of pissed though, because I can do that in PHP in five minutes.... Anyway.

I think this is best added to /sapphire/core/model/sitetree.php and would go along the ways of

public function getNextPage() {
return DataObject::get_one("SiteTree", "insert smart SQL here" );
}

I have the following questions....

a. can someone tell me how to write that function
b. what are the chances of making it part SS?

I am desperate - so any help greatly appreciated!

Nicolaas

Avatar
Sam

2 June 2007 at 6:24pm Administrator, 679 Posts

Do this

$pages = DataObject::get("SiteTree", "ParentID = $this->ID AND Sort > $this->Sort", "Sort", "", 1)
if($pages) return $pages->First();

For prev

$pages = DataObject::get("SiteTree", "ParentID = $this->ID AND Sort > $this-<Sort", "Sort DESC", "", 1)
if($pages) return $pages->First();

Avatar
Nicolaas

5 June 2007 at 12:19am Forum Moderator, 213 Posts

Hi Sam

Thanks for your help.

For those interested, this is what I used in the end (in the mysite/code/page.ss file) - sorry for all the site specific details...

public function NextPage() {
$pages = DataObject::get("SiteTree", "ParentID = $this->ParentID AND Sort > $this->Sort", "Sort", "", 1);
foreach($pages as $page) {
return '<a href="' . $page->Link() . '" id="next" title="next page: ' . Convert::raw2xml($page->Title) . '"><img src="/mysite/images/next.gif" alt="next page" width="14" height="30" /></a>';
}
}
public function PreviousPage() {
$pages = DataObject::get("SiteTree", "ParentID = $this->ParentID AND Sort < $this->Sort", "Sort DESC", "", 1);
foreach($pages as $page) {
return '<a href="' . $page->Link() . '" id="prev" title="previous page: ' . Convert::raw2xml($page->Title) . '"><img src="/mysite/images/prev.gif" alt="previous page" width="14" height="30" /></a>';
}
}

Hope that helps.

Cheers

Nicolaas

Avatar
Nicolaas

5 June 2007 at 10:42am Forum Moderator, 213 Posts

just to add to that.

The links can be displayed by adding $NextPage or $PreviousPager to your template (e.g. mysite/templates/page.ss)

Hope that helps.

Nicolaas

Avatar
Sam

6 June 2007 at 9:47am Administrator, 679 Posts

This is fine for your specific purpose, but for a more general NextPage() feature, I would just return the data object.

You can then put

<% control NextPage %>
<a href="$Link">$Title</a>
<% end_control %>

Or

<a href="$NextPage.Link">$NextPage.Title</a>

Into your template. This keeps more HTML in your template file, which is officially a good thing, particularly if you've got a separate person helping with design.

Avatar
Nicolaas

6 June 2007 at 11:44pm Forum Moderator, 213 Posts

Thanks Sam - totally hear what you are saying about having the html in the template is this exactly what attracted me to SS. You guys have done a great job in this regard!

Avatar
pac

31 July 2008 at 5:02am (Last edited: 31 July 2008 5:57am), Community Member, 25 Posts

this is great, thank you. should be implemented in core,

Thanks for your help, and if there are any freelance developpers available out there, feel free to contact me for module and specific developments.

running ss2.2.2